1819791 Members
3166 Online
109607 Solutions
New Discussion юеВ

tar a list of files...

 
SOLVED
Go to solution
jmckinzie
Super Advisor

tar a list of files...

Team,

This seems pretty basic but I am unsure.
I have afile located in /tmp that has a list of files....i want to tar each of those files into one tar ball.

so, lets say the filename of the list of files is /tmp/aa how do i tell the tar to go get those files nad only create on tar ball?
8 REPLIES 8
Geoff Wild
Honored Contributor

Re: tar a list of files...

tar cvf aa.tar `cat /tmp/aa`

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
James R. Ferguson
Acclaimed Contributor
Solution

Re: tar a list of files...

Hi Jody:

# tar -cvf myarchive `cat /tmp/aa`

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: tar a list of files...

Hi Jody,

if there are many files in /tmp/myfiles to be archived, you can use 'pax', which can write tar-format but can read the files to be archived from stdin as well:
pax -w -f myarchive.tar
That way you won't get a 'arglist too long' error.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Srimalik
Valued Contributor

Re: tar a list of files...

cat /tmp/aa | xargs tar -cvf aa.tar
abandon all hope, ye who enter here..
Steven Schweda
Honored Contributor

Re: tar a list of files...

Or, if you use (the option-rich) GNU "tar":

--files-from=file
-T file
tar will use the contents of file as a list of archive members or files to
operate on, in addition to those specified on the command-line. See files.


http://www.gnu.org/software/tar/
http://www.gnu.org/software/tar/manual/
Peter Nikitka
Honored Contributor

Re: tar a list of files...

Hi,

I want to warn, using the xargs-solution above:
Since - with a long filename list - the xargs calls multiple times and the option 'c' is used, the tarfile will contain only the files of its last execution.
An update/append option is possible, however.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Dennis Handly
Acclaimed Contributor

Re: tar a list of files...

>Srikrishan: cat /tmp/aa | xargs tar -cvf aa.tar

This will just overwrite aa.tar when xargs repeats. Also, you should not be using cat:
$ xargs tar -cvf < /tmp/aa

Similarly use:
$ tar -cvf aa.tar $(< /tmp/aa)

Of course Peter and Steven have the solution for infinite number of files.

jmckinzie
Super Advisor

Re: tar a list of files...

I have figured this out via the help provided.