Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tar archiving that takes input from a list of files

People also ask

Can a tar command Use a standard input for its file list?

tar cannot read in file data from stdin for creating an archive, since then tar will have no way of knowing what a file is - where one begins or ends, what its path and metadata is.

How do I extract only certain files from a tar?

Now, if you want a single file or folder from the “tar” file, you need to use the name of the “tar” file and the path to a single file in it. So, we have used the “tar” command with the “-xvf” option, the name of the “tar” file, and the path of a file to be extracted from it as below.


Yes:

tar -cvf allfiles.tar -T mylist.txt

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


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

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

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)

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

For me on AIX, it worked as follows:

tar -L List.txt -cvf BKP.tar