|
Home > Archive > Unix administration > January 2007 > How to create a tar + gzip from a listing of file names.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to create a tar + gzip from a listing of file names.
|
|
| Daryl Rose 2007-01-24, 7:19 pm |
| 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
| |
| Bo Yang 2007-01-25, 7:19 am |
| Daryl Rose :
> 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
>
Does the following code works for you ?
tar cvf BKUPTST_$DATE.tar $(sed 's/\n/ /g' < archive.lst)
| |
| Doug Freyburger 2007-01-25, 1:19 pm |
| "Daryl Rose" <jzl...@yahoo.com> wrote:
>
> I have a file with about a dozen file names in it. I want to create a
> tar/gzip of those files.
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.
| |
| Stephane CHAZELAS 2007-01-25, 7:25 pm |
| 2007-01-25, 18:56(+08), Bo Yang:
[...]
> Does the following code works for you ?
>
> tar cvf BKUPTST_$DATE.tar $(sed 's/\n/ /g' < archive.lst)
$(....) 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
|
|
|
|
|