Linux 从文件列表中获取输入的 Tar 归档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8033857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tar archiving that takes input from a list of files
提问by neversaint
I have a file that contain list of files I want to archive with tar.
Let's call it mylist.txt
我有一个文件,其中包含要使用 tar 存档的文件列表。让我们称之为mylist.txt
It contains:
它包含了:
file1.txt
file2.txt
...
file10.txt
Is there a way I can issue TAR command that takes mylist.txt
as input?
Something like
有没有办法可以发出mylist.txt
作为输入的TAR 命令?就像是
tar -cvf allfiles.tar -[someoption?] mylist.txt
So that it is similar as if I issue this command:
所以它就像我发出这个命令一样:
tar -cvf allfiles.tar file1.txt file2.txt file10.txt
采纳答案by Martin York
Yes:
是的:
tar -cvf allfiles.tar -T mylist.txt
回答by Simon Richter
Assuming GNU tar (as this is Linux), the -T
or --files-from
option is what you want.
假设 GNU tar(因为这是 Linux),-T
or--files-from
选项就是你想要的。
回答by Jan
On Solaris, you can use the option -I to read the filenames that you would normally state on the command line from a file. In contrast to the command line, this can create tar archives with hundreds of thousands of files (just did that).
在 Solaris 上,您可以使用选项 -I 从文件中读取通常在命令行中声明的文件名。与命令行相反,这可以创建包含数十万个文件的 tar 存档(就是这样做的)。
So the example would read
所以这个例子会读
tar -cvf allfiles.tar -I mylist.txt
回答by woot
You can also pipe in the file names which might be useful:
您还可以输入可能有用的文件名:
find /path/to/files -name \*.txt | tar -cvf allfiles.tar -T -
回答by barush
Some versions of tar, for example, the default versions on HP-UX (I tested 11.11 and 11.31), do not include a command line option to specify a file list, so a decent work-around is to do this:
某些版本的 tar,例如 HP-UX 上的默认版本(我测试了 11.11 和 11.31),不包含用于指定文件列表的命令行选项,因此一个不错的解决方法是这样做:
tar cvf allfiles.tar $(cat mylist.txt)
回答by Cassiano Bucci
For me on AIX, it worked as follows:
对于我在 AIX 上,它的工作方式如下:
tar -L List.txt -cvf BKP.tar