Removing files older than one week in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing files older than one week in a directory
# 1  
Old 05-25-2009
Removing files older than one week in a directory

Hi,
I need a shell script to remove the files older than a week in a directoy and if necessary to zip the files.
# 2  
Old 05-25-2009
Code:
check "find" command.

# 3  
Old 05-25-2009
find and exec

Quote:
Originally Posted by sudhakaryadav
Hi,
I need a shell script to remove the files older than a week in a directoy and if necessary to zip the files.
hello,

for example:

By crontab use :

40 20 * * 1-6 find /path -name "*" -mtime +8 -exec rm -f {} \;

Delete all files older than 8 days in the directory by cron on day 1-6 at 08:40 pm.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help deleting files one week older

Hi, I need to delete *.bad files which are 1 week old. How can I achieve that. I tried doing through below script but it deletes all the files. find ./ -mtime +7 -exec rm *.bad {} \; The below one works but i want to delete only files with .bad extension find . -mtime +7 | xargs rm (2 Replies)
Discussion started by: Gangadhar Reddy
2 Replies

2. Shell Programming and Scripting

Removing older version files

Hi, I have a direcory as mentioned below: /development/arun/cycdt/ unser the above i have directories /2013 /2012 /2011 ...... ..... /2000 I need to write a script which can delete the nth version of the directories. as in if n=10 then the script should arrange the directories in... (2 Replies)
Discussion started by: Arun Mishra
2 Replies

3. 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

4. Shell Programming and Scripting

Delete files older than 10 Days in a directory

Hi All I want to remove the files with name like data*.csv from the directory older than 10 days. If there is no files exists to remove older than 10 days, It should not do anything. Thanks Jo (9 Replies)
Discussion started by: rajeshjohney
9 Replies

5. UNIX for Advanced & Expert Users

removing files older than n days

Hi, on AIX 6.1, is there any commande line to remove the files older than n days in a directory ? Thanks. (2 Replies)
Discussion started by: big123456
2 Replies

6. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

Hi, Friends, I am writing a script to delete all the files which are there for more than 3 weeks. I have tried this : find /home/appl/backup -type f -mtime +21 -exec rm -f {} \; But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded... (3 Replies)
Discussion started by: rajsharma
3 Replies

7. Shell Programming and Scripting

Find files in a directory which are older than 2 hrs

hi all, I need to find files in a directory which are older than N hrs... n can be 1,2,3,.. etc when tried using -mtime option it gives all the files in the last 24hrs from the current time . please help me out on this .. thanks (8 Replies)
Discussion started by: sparks
8 Replies

8. UNIX for Dummies Questions & Answers

Removing files older than 7 days

Script help, I need to delete files that are older than 7 days. I do that automatically but I know that a cron job can do the job for me. Any help is greatly appreciated, as you can see, I am a DOS or WINDOWS guy. Little on UNIX. Thanks (3 Replies)
Discussion started by: texasoeb
3 Replies

9. Shell Programming and Scripting

RE:backup files older then 24hrs to a new directory .

How do you move (mv) files to a backup directory from a particular directory when the files are older the 24hrs copied from a batch script run every 24 hrs. Would you use find or some kind of timestamp.timestamp="$(date +'%m%d%I%M')" (2 Replies)
Discussion started by: amceyeson
2 Replies

10. Shell Programming and Scripting

removing files after 6 hours or older

What is the command to remove files that are generated 6 hours or older? The find and remove tells only how to remove if the file is one day old or more. Appreciate quick reply. Thanks (3 Replies)
Discussion started by: gthokala
3 Replies
Login or Register to Ask a Question