gzip files older than 1 months


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gzip files older than 1 months
# 1  
Old 11-21-2010
gzip files older than 1 months

Hello,
I want to gzip files in a folder in bulk i.e. all files older than 1 month should be in *.gz format. Could you please suggest how this can be achieved. Thanks.
Regards,
Alok
# 2  
Old 11-21-2010
It depends if you want to make one archive of them all, of leave them as individual files. If it is the latter, then the easiest will be with a find command, e.g.
Code:
find $dir -type f ! -name "*.Z" -mtime +31 -print | xargs compress

I know that this will create plain unix compressed files, but you get the idea.

Beware that this will follow symbolic links to other filesystems and will trawl through all directories /filesystems under $dir. The -type f and ! -name "*.Z" will ensure that you only get files that are not already compressed.


If you want a single archive of the files, there are a number of options depending on operating system. AIX for one allows you to provide an input list to tar, so:-
Code:
find $dir -type f ! -name "*.Z" -mtime +31 -print >/tmp/target_files
tar -cvL /tmp/target_files - |compress> $my_archive

Some others do not, so you have to be a little inventive, perhaps creating a temporary sub-directory, moving the files there and then tar/compress the whole thing in one go, e.g.
Code:
mkdir mytempdir
find $dir -type f ! -name "*.Z" -mtime +31 -exec mv {} mytempdir \;
cd mytempdir
tar -cvf - . | compress >> ../$my_archive
cd ..
rm -r mytempdir

Beware that this is riskier though. Ensure you have good error checking. If you run out of space during the tar/compress, the above will probably still delete the mytempdir and all the contents which you have just failed to secure.

Make sure you are happy with your backups to external media before you put something like this in place.



I hope that this helps.


Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting files and directory's older than 3 months

I have a qnap TS259 that is running ubuntu. Have successfully setup back scripts that are initiated by cron. I would like to create a couple scrypts that would operate on the recycle bins for both drives. Just want to be able to run the script manually that would walk through both directories... (13 Replies)
Discussion started by: mackconsult
13 Replies

2. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

3. UNIX and Linux Applications

Firefox 10 keeps losing history older than 2 months

Can anyone explain why Firefox 10 keeps losing history older than 2 months? (1 Reply)
Discussion started by: cokedude
1 Replies

4. Shell Programming and Scripting

Command to Count the files which is Older than 3 months?

Hi Gurus the count of files in a particular Directory... ls -lrth | grep -c ^- can any one share the command to Count the files which is Older than 3 months So please help me out in this Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

5. Shell Programming and Scripting

need a code for moving the log files older than 2 months

Hi Viewer, I need logic code for moving the logs files from one directory to another directory. source :/xxxxxx/ xxxxxx / xxxxxx / xxxxxx / log --- under log directory we have so many files from last two years Here I need to check the files older than two months and I need to move in... (5 Replies)
Discussion started by: munna_su
5 Replies

6. Shell Programming and Scripting

Delete 6 months old files

Hi, Iam trying to delete 6 months old files. Iam using the following script -ctime +190 -type f -exec echo rm {} \; Iam getting an error saying -ctime not found. (6 Replies)
Discussion started by: Sompalle Jalaja
6 Replies

7. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

8. UNIX for Dummies Questions & Answers

deleting files with dates 3 months ago

please help me with this????? :confused: :confused: i need to create a program that will run in unix that will delete all files in a given directory that is at least 3 months old. first the program will need to automatically know what date it is right now to determine the files it will... (3 Replies)
Discussion started by: godalle
3 Replies

9. UNIX for Dummies Questions & Answers

Last modification times of files less than 6 months old

How do I get the modification time for files less than 6 months old? (It seems for fles as old or older than this I get to see only the day,month and year. I tried the option -u but it gives me the last accessed time) (1 Reply)
Discussion started by: Abhishek Ghose
1 Replies

10. Shell Programming and Scripting

Listing files older than 2 months

A script or command to list files older than 2 months in a specified directory and remove it. (3 Replies)
Discussion started by: pbekal
3 Replies
Login or Register to Ask a Question