Compress folders older than x days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compress folders older than x days
# 1  
Old 07-03-2015
Compress folders older than x days

hello everyone.
in /opt/abc every night there is a new folder created. in that folder there is aseries of files created for that day.
i would like to run a script every Sunday night at 02:00 to compress each file separately (preserving its name) who is older than 2 days.
i have found this command
find /opt/abc/ -mtime +2 | xargs tar -czvPf /opt/older_log_$(date +%F).tar.gz

but i do not know how to edit it to make suitable for my needs. I would appreciate any help available.
Thanks in advance.
# 2  
Old 07-03-2015
Each file separately gziped
Code:
find /opt/abc/ -type f -mtime +2 \! -name '*.gz' -exec gzip {} \;

# 3  
Old 07-04-2015
Please also note that if have alot of files, you will gain performance by replacing \; with \+ in MadeinGermany find statement, since gzip can accept multiple files as arguments.

Use cron to run that at desired times.

Gzip will also ignore gz suffixed files, printing that on stderr.

Regards
Peasant.
These 2 Users Gave Thanks to Peasant For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i move folders and its content if folder is older than 1,5 days and keep subdirs in bash?

Hello all, do you know any way i can i move folders and its content if folder is older than 1,5 days in bash? I tried: find /home/xyz/DATA/* -type d -ctime +1.5 -exec mv "{}" /home/xyz/move_data_here/ \;All i got was that Files from DATA /home/xyz/DATA/* ended messed up in... (1 Reply)
Discussion started by: ZerO13
1 Replies

2. Shell Programming and Scripting

Script to compress and delete the older logs

Hello Guys, Can you please help me with a script which zips the older log files(1-2 weeks) and delete them? I want to run the script manually instead of setting it up in a cron job. Appreciate your help. Regards, Kris (6 Replies)
Discussion started by: kriss.gv
6 Replies

3. Shell Programming and Scripting

Compress and delete folders

Hello, can someone help me to create a short script that tar.gz all folders form a specific folder and the delete the folders themself (without deleting the tar.gz created files)? Moreover I'd like to add it on crontab and run it each day. For example: in /tmp I have: /tmp/test/test1... (7 Replies)
Discussion started by: mab80
7 Replies

4. UNIX for Dummies Questions & Answers

How to compress the directories which is older than 7 days?

Hi all, how to compress the directories which is older 7 days. If any one knows please help me this is urgent. Thanks in advance (3 Replies)
Discussion started by: rameshpagadala
3 Replies

5. Shell Programming and Scripting

Find and delete files and folders which are n days older from one unix server to another unix server

Hi All, Let me know how can i find and delete files from one unix server to another unix server which are 'N' days older. Please note that I need to delete files on remote unix server.So, probably i will need to use sftp, but question is how can i identify files and folders which are 'N'... (2 Replies)
Discussion started by: sachinkl
2 Replies

6. UNIX for Dummies Questions & Answers

Files older than 50 days

Hi All, OS :- HP-UX wm5qa B.11.23 U ia64 1119805695 unlimited-user license I need to search files older than 50 days. I've used following command in order to search desired files, I also discoverd, it's showing today's files as well. Do you have any clue with this ? wmqa1> find .... (4 Replies)
Discussion started by: alok.behria
4 Replies

7. Shell Programming and Scripting

Delete folders older than 30 days

Dear all, i use incremental backup my data with .zip to my hard drive. what i need is i don't want the old .zip file older than 30 days. how to write a shell script automatically remove my external hard disc zip backup folders older than 30 days? Regards, (2 Replies)
Discussion started by: joneggk
2 Replies

8. UNIX Desktop Questions & Answers

Find files older than 10 days

What command arguments I can use in unix to list files older than 10 days in my current directory, but I don't want to list the hidden files. find . -type f -mtime +15 -print will work but, it is listing all the hidden files., which I don't want. (4 Replies)
Discussion started by: Pouchie1
4 Replies

9. Shell Programming and Scripting

How to tar, compress and remove files older than two days

Hi, I'm Eddy from Belgium and I've the following problem. I try to write a ksh script in AIX to tar, compress and remove the original *.wav files from the directory belgacom_sf_messages older than two days with the following commands. The problem is that I do not find a good combination... (4 Replies)
Discussion started by: edr
4 Replies

10. Shell Programming and Scripting

delete files and folders older than 3 days

find /basedirectory -type f -mtime +3 >> /tmp/tempfile find /basedirectory -type d -mtime +3 >> /tmp/tempfile mailx -s "List of removed files and folders" myemail@domain.com < /tmp/te mpfile rm /tmp/tempfile find /basedirectory -type f -mtime +3 -exec rm {} \; find /basedirectory -type d... (7 Replies)
Discussion started by: melanie_pfefer
7 Replies
Login or Register to Ask a Question