I have a list of files I wish to archive with tar in a file. Let’s call it mylist.txt for short.
file1.txt file2.txt ... file10.txt
Is there a way to use the TAR command with mylist.txt as the input? anything along those lines
tar -cvf allfiles.tar -[someoption?] mylist.txt
As if I were to issue the following command:
tar -cvf allfiles.tar file1.txt file2.txt file10.txt
Asked by neversaint
tar -cvf allfiles.tar -T mylist.txt
Answered by Martin York
The -T or —files-from option is what you want if you’re using GNU tar (since this is Linux).
Answered by Simon Richter
You can also pipe in the file names which might be useful:
find /path/to/files -name \*.txt | tar -cvf allfiles.tar -T -
Answered by woot
Because some versions of tar, such as the default versions on HP-UX (I tried 11.11 and 11.31), lack a command-line option to supply a file list, this is a good workaround:
tar cvf allfiles.tar $(cat mylist.txt)
Answered by barush
On Solaris, you can use the -I option to read filenames from a file instead of specifying them on the command line. Unlike the command line, this allows you to generate tar archives with hundreds of thousands of files (just did that).
As an example, consider the following:
tar -cvf allfiles.tar -I mylist.txt
Answered by Jan
Post is based on https://stackoverflow.com/questions/8033857/tar-archiving-that-takes-input-from-a-list-of-files