Operating System - HP-UX
1748281 Members
4010 Online
108761 Solutions
New Discussion юеВ

tar and gunzip mutiple files

 
gany59
Regular Advisor

tar and gunzip mutiple files

Hello techies,

In one of my server /var is 95%. so i find out the old log files in /var/adm/sa. some 100 log files are there in the name like sa1 sa2 sa3.
so how can i tar all those files into a single file and gzipped that one.

Please let me know.

Thanks in advance!!
6 REPLIES 6
Hakki Aydin Ucar
Honored Contributor

Re: tar and gunzip mutiple files

Go to directory that you have file to compress;
# cd /var/adm/sa
# tar -cvf - * | gzip -9 -c > directory.tgz
Steven Schweda
Honored Contributor

Re: tar and gunzip mutiple files

> Dec 28, 2010 07:45:43 GMT 3 pts

What didn't you like? If you want a more
detailed answer, then you might try starting
with a more detailed question.


> # cd /var/adm/sa
> # tar -cvf - * | [...]

I'd probably do it differently:

cd /
tar -cf - var/adm/sa | [...]

That way I wouldn't forget whence the files
came originally. But I don't know exactly
which files you wish to archive.
Dennis Handly
Acclaimed Contributor

Re: tar and gunzip mutiple files

>Hakki: tar -cvf - * | gzip -9 -c > directory.tgz

You need to be careful about using "*" and then writing to a file in the same directory. You'll get a tar feedback loop. :-)
Hakki Aydin Ucar
Honored Contributor

Re: tar and gunzip mutiple files

>Dennis:You need to be careful about using "*" and then writing to a file in the same directory. You'll get a tar feedback loop. :-)

That is right, thank you Dennis for heads up .
rmueller58
Valued Contributor

Re: tar and gunzip mutiple files

with gnu tar you can

use the
tar -czvf /mount-withfreespace/filename.tar.gz /var/adm/sa*
Steven Schweda
Honored Contributor

Re: tar and gunzip mutiple files

> tar -czvf [...] /var/adm/sa*

There's a reason I suggested:

cd /
tar -cf - var/adm/sa [...]

instead of:

tar -cf - /var/adm/sa [...]

One is easier to extract to a non-original
location.