Link to home
Start Free TrialLog in
Avatar of lsbrown1
lsbrown1

asked on

How to gzip multiple files in unix

I need to be able to  gzip multiple .pdf and .txt files with a date stamp(filenamemmyydd) in the same folder in unix daily. Is a simple command or script to execute to perform this task?
Avatar of lsbrown1
lsbrown1

ASKER

I tried below but it didn't work. lcd path and cd path are pointing to the same path. *.txt files already exist in path.
ftp -n xxx.xx.xx.xx <<END
username password
lcd /xxx/xxx/xxx
type binary
mget *.pdf
cd /xxx/xxx/xxx
gzip -c *.pdf *.txt > xx_xxxxx.`date +%Y-%m-%d`.gz
bye
END
Avatar of Omid Helal, PMP®
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> gzip -c *.pdf *.txt > xx_xxxxx.`date +%Y-%m-%d`.gz
This command will create one .gz file that consists of the concatenated input files (pdf and txt) and then compressed.

Is this what you want? Or do you want to add the files to an archive first and them compress? In that case use this:
tar cfz  xx_xxxxx.`date +%Y-%m-%d`.gz *.pdf *.txt

Open in new window

This way you will get one compressed archive containing each individual file (pdf and txt).
gzip only works on individual files.  Use tar or zip instead, eg:

zip file.`date +%Y-%m-%d.zip` *.pdf *.txt

Open in new window


or

tar czf  file.`date +%Y-%m-%d.gz` *.pdf *.txt

Open in new window


or if your tar version doesn't support the -z flag, do

tar cf - *.pdf *.txt | gzip > file.`date +%Y-%m-%d.gz`

Open in new window

Did you try unzipping the .gz file that you get from the answer you chose? You cannot get individual .txt and .pdf files back from it. Sure you selected the right answer here?
lsbrown1, as gerwinjansen as already mentioned, the solution you have chosen will make it extremely difficult to extract your individual PDF files.
I would replace

gzip -c *.pdf *.txt > xx_xxxxx.`date +%Y-%m-%d`.gz

by

zip xx_xxxxx.`date +%Y-%m-%d` *.pdf *.txt