• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1585
  • 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 OmarkhailCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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