开发者

Create a tar file in a subdirectory of the directory to be archived

I'd like to create a tar file of all the files in a directory minus sub-directory's in that directory and pla开发者_高级运维ce that tar file in one of the sub-directory's. For example, I have several .txt files in /test and also another directory in /test called ArchivedFiles. I'd like to tell the tar command to archive all of the .txt files and place it in /test/ArchivedFiles.

How do I go about doing this?


tar cf test/foo/test.tar -- `find test  -maxdepth 1 -name '*.txt' -type f`

I think that should do what you want.

An option which will not work due to the age of your tar command is:

find test -maxdepth 1 -type f -name '*.txt' -print0 | tar -cf test/foo/test.tar --null --files-from -

You are having problems, so you can try the following commands:

tar cf test/foo/test.tar `find test  -maxdepth 1 -name '*.txt' -type f`
echo tar cf test/foo/test.tar `find test  -maxdepth 1 -name '*.txt' -type f`
tar c f test/foo/test.tar `find test  -maxdepth 1 -name '*.txt' -type f`
find test  -maxdepth 1 -name '*.txt' -type f

And pastebin the output so that we can see what is happening.

Given that find is very legacy as well, let us try the following:

tar cf test/foo/test.tar test/*.txt


The following command will work. It will place any subdirectories into the tar but it doesn't put the contents of those subdirectories into the tar. This means that if you put the tar into a subdir you won't have to worry about it putting itself inside itself inside itself...

For example, if you want to put all of the files which are in the current directory into a tar file called mytar.tar which is in a subdir called d1:

tar --no-recursion -cvf d1/mytar.tar *
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜