Tech Support > Operating Systems > UNIX / Variants > How to create a tar + gzip from a listing of file names.
How to create a tar + gzip from a listing of file names.
Posted by Daryl Rose on January 24th, 2007


I have a file with about a dozen file names in it. I want to create a
tar/gzip of those files.

Currently I have it written this way:

CNT=0
while read line
do
if [ $CNT -eq 0 ]
then
tar cvf BKUPTST_$DATE.tar $line
CNT=1
else
tar rvf BKUPTST_$DATE.tar $line
fi
done < $APP_PATH/$APP/$DB/archive.lst

gzip BKUPTST_$DATE.tar

This works, but I would like to find a better way to do this. BTW, this
is Unix tar, not a GNU tar. If it were GNU, then I know there are
options to read in from a file and compress all in one step.

Anyone have any idea's?

Thank you.
Daryl

Posted by Bo Yang on January 25th, 2007


Daryl Rose :

tar cvf BKUPTST_$DATE.tar $(sed 's/\n/ /g' < archive.lst)

Posted by Doug Freyburger on January 25th, 2007


"Daryl Rose" <jzl...@yahoo.com> wrote:
tar -cf - -I file | gzip > tarball.tgz

file should contain nothing but the names, one to a line, preferably
without a leading /.

If your tar doesn't have a -I option, consider:

tar cf - ` cat file ` | ...

which will work as long as the number/character-count of the files
does not blow the shell buffer.


Posted by Stephane CHAZELAS on January 25th, 2007


2007-01-25, 18:56(+08), Bo Yang:
[...]
$(....) splits upon space, tabs and newlines by default and also
expands the wildcards. So you don't need to convert newlines to
spaces. You should rather make sure $(...) only splits on
newlines, and doesn't expand the wildcards:

IFS='
'
set -f

--
Stéphane


Similar Posts