Tar archiving that takes input from a list of files

时间秒杀一切 提交于 2019-11-28 13:48:15

问题


I have a file that contain list of files I want to archive with tar. Let's call it 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

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 

回答1:


Yes:

tar -cvf allfiles.tar -T mylist.txt



回答2:


Assuming GNU tar (as this is Linux), the -T or --files-from option is what you want.




回答3:


You can also pipe in the file names which might be useful:

find /path/to/files -name \*.txt | tar -cvf allfiles.tar -T -



回答4:


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 cvf allfiles.tar $(cat mylist.txt)



回答5:


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).

So the example would read

tar -cvf allfiles.tar -I mylist.txt



回答6:


For me on AIX, it worked as follows:

tar -L List.txt -cvf BKP.tar


来源:https://stackoverflow.com/questions/8033857/tar-archiving-that-takes-input-from-a-list-of-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!