Changing the file name while compressing

Hi,

Is there any way to change the file name while compressing ? using Compress and gzip and tar ?

Say, I have a file foo.txt - so I have to compress this file and the resultant file name is foo.txt_20130113.gz or foo.txt_20130113.Z

This to be done while performing the compression operation and the UNIX file modification time should be changed to time of creating the compressesd file.

Longback I done using zip / jar command. Unfortunately, I dont have zip or jar installed in my AIX currently.

Any ideas ?

Thanks.

Use -S option to specify the suffix:-

gzip -S "_20130113.gz" foo.txt

You can use the '-c' option and write to a file name of your choice, this does not replace the original file so you would have to remove it:

gzip -cvf foo.txt > foo.txt.gz

Or you could immediately after the gzip command run the touch command to change the '.gz' files timestamp:

gzip -vf foo.txt
touch foo.txt.gz