• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2462
  • Last Modified:

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?
0
lsbrown1
Asked:
lsbrown1
  • 2
  • 2
  • 2
  • +2
1 Solution
 
lsbrown1Author Commented:
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
0
 
Omid OmarkhailSenior Technical ConsultantCommented:
0
 
omarfaridCommented:
You can not run the gzip command before you exit ftp. Try this

ftp -n xxx.xx.xx.xx <<END
username password
lcd /xxx/xxx/xxx
type binary
mget *.pdf
bye
END

cd /xxx/xxx/xxx
gzip -c *.pdf *.txt > xx_xxxxx.`date +%Y-%m-%d`.gz
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Gerwin Jansen, EE MVETopic Advisor Commented:
>> 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).
0
 
TintinCommented:
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

0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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?
0
 
TintinCommented:
lsbrown1, as gerwinjansen as already mentioned, the solution you have chosen will make it extremely difficult to extract your individual PDF files.
0
 
omarfaridCommented:
I would replace

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

by

zip xx_xxxxx.`date +%Y-%m-%d` *.pdf *.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now