开发者

tar on one line?

开发者 https://www.devze.com 2023-02-04 12:26 出处:网络
For some tar adept, I\'m sure all of the following could be achieved on one line? mkdir si开发者_JS百科te_media/media

For some tar adept, I'm sure all of the following could be achieved on one line?

mkdir si开发者_JS百科te_media/media
cp fixtures/media.tar site_media/media/media.tar
cd site_media/media/
tar -xvf media.tar
rm media.tar 
cd ../../


There is really no need to copy the tar file if you are only going to delete the copy anyway. This will work for you without the copying, deleting, and changing directories:

mkdir site_media/media; tar -xvf fixtures/media.tar -C site_media/media


Comedy answer:

mkdir site_media/media && cp fixtures/media.tar site_media/media/media.tar && 
cd site_media/media/ && tar -xvf media.tar && rm media.tar && cd ../../


Slightly more serious: I don't know of a way to create the base directory as part of a single tar, but it can be reduced somewhat:

mkdir -p site_media/media
tar -xvf fixtures/media.tar -C site_media/media

This avoids the delete by avoiding the copy in the first place. The C option in extract mode means 'change to this directory after opening the archive but before extracting anything'.

As @Steve-o humorously points out, you can combine lines with &&, which also has the effect of Boolean short-circuiting: stopping if a command fails.

0

精彩评论

暂无评论...
验证码 换一张
取 消