nev*_*int 146 unix linux tar archive
我有一个文件,其中包含我想用tar存档的文件列表.我们称之为mylist.txt
它包含:
file1.txt
file2.txt
...
file10.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法可以发出mylist.txt作为输入的TAR命令?就像是
tar -cvf allfiles.tar -[someoption?] mylist.txt
Run Code Online (Sandbox Code Playgroud)
所以它就像我发出这个命令一样:
tar -cvf allfiles.tar file1.txt file2.txt file10.txt
Run Code Online (Sandbox Code Playgroud)
Mar*_*ork 231
是:
tar -cvf allfiles.tar -T mylist.txt
Run Code Online (Sandbox Code Playgroud)
Sim*_*ter 81
假设GNU tar(因为这是Linux),-T或者--files-from选项就是你想要的.
woo*_*oot 28
您还可以输入可能有用的文件名:
find /path/to/files -name \*.txt | tar -cvf allfiles.tar -T -
Run Code Online (Sandbox Code Playgroud)
bar*_*ush 13
某些版本的tar(例如,HP-UX上的默认版本(我测试过11.11和11.31))不包含用于指定文件列表的命令行选项,因此一个体面的解决方法是执行此操作:
tar cvf allfiles.tar $(cat mylist.txt)
Run Code Online (Sandbox Code Playgroud)
在Solaris上,您可以使用选项-I来读取通常在文件命令行中声明的文件名.与命令行相比,这可以创建包含数十万个文件的tar存档(就是这样做).
所以这个例子就是这样的
tar -cvf allfiles.tar -I mylist.txt
Run Code Online (Sandbox Code Playgroud)
小智 7
对于 AIX 上的我来说,它的工作原理如下:
tar -L List.txt -cvf BKP.tar
Run Code Online (Sandbox Code Playgroud)