Deleting files older than 14 days automatically


 
Thread Tools Search this Thread
Operating Systems AIX Deleting files older than 14 days automatically
# 1  
Old 05-09-2011
Deleting files older than 14 days automatically

Hi

In my aix server under the location "/usr/sap/SAPXI/extract", I have a lot of log files.

I need a script which is to be added in crontab so that the files and directories older than 14 days should get deleted automatically from the location "/usr/sap/SAPXI/extract".

Please advise me. Thanks
# 2  
Old 05-09-2011
Create script like this:
Code:
#!/bin/sh
find /usr/sap/SAPXI/extract -type f -mtime +14 -exec rm {} \;


Last edited by bartus11; 05-09-2011 at 09:00 AM..
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 05-10-2011
If you want to delete the directories as well remove
Code:
-type f

from the command. Also be aware that if the extract directory ever meets the 14 day criteria that it will be deleted as well. Maybe someone else knows how to exclude the base search directory when using the find command, as I don't. You could avoid this by touching the directory before running the find command which just updates the time stamps on that directory. Not likely to be an issue if this directory is accessed and written to often but wanted you to be aware of it.

Code:
#!/bin/ksh
touch /usr/sap/SAPXI/extract
find /usr/sap/SAPXI/extract -mtime +14 -exec rm -rf {}\;

Also be aware that
Code:
-mtime

deals with modifed time. You may have files in that directory that are being accessed but not modified so you may consider using
Code:
-atime

value to cover yourself there, that is if access times are a factor in your environment.

Last edited by juredd1; 05-10-2011 at 01:05 PM.. Reason: Correct Syntax
# 4  
Old 05-10-2011
This is difficult to achieve. The moment you delete a file or directory, the timestamp on the directory containing that file or directory changes. Unless this is a very simple tree "rm -rf" is out of the question because it is not unusual for subdirectories to have a later modification time than the parent.
If the requirement matches it may be better to delete old files then susequently delete empty directories from the bottom of the tree up (not an easy script).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script for Deleting files older than 14 days automatically

we need to have periodic clean up implemented in our sap directory \\sapds\PR1\int\scm\snp\outbound\snapshot. which needs unix script for Deleting files older than 14 days automatically in sap system unix os. (1 Reply)
Discussion started by: kvkreddy_b2w
1 Replies

2. Shell Programming and Scripting

Deleting entries older than 7 days from a file

Hi, I have a file which contains entries in this format. my-bin.000140 my-bin.000141 my-bin.000142 my-bin.000143 my-bin.000144 my-bin.000145 my-bin.000146 my-bin.000147 my-bin.000148 my-bin.000149 my-bin.000150 my-bin.000151 my-bin.000152 my-bin.000153 my-bin.000154... (2 Replies)
Discussion started by: arijitsaha
2 Replies

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

4. Shell Programming and Scripting

deleting files older than 7 days

Hi Guys, I am new to unix I am looking for a script to delete files older than 7 days but i also want to exclude certain directories (like arch,log .....) and also some files with extensions ( like .ksh, .ch, ..............) Thanks (1 Reply)
Discussion started by: MAYAMAYA0451
1 Replies

5. Shell Programming and Scripting

How to find files older than 30 days

Dear Friends, I have two queries. 1) I want to see the list of folders which were created 29 days ago. 2) I want to see the folders in which last created file is older than 29 days. Can it be done? Thank you in advance Anushree (4 Replies)
Discussion started by: anushree.a
4 Replies

6. Solaris

Copying files older then 2 days

Hi everyone :) I have a little question here, at my work, we have a system running Solaris 10 - with an attached EMC SAN, the SAN is running out of space, and we are moveing the data to a new EVA SAN. The problem here is, that there are over 35.000.000 files on the system, and constantly 30... (4 Replies)
Discussion started by: Skovsen
4 Replies

7. UNIX for Dummies Questions & Answers

Deleting specfic files older than N days

Hello, I am trying to delete specific files older than 7 days that start with FSTRnnnn (nnnn=sequnce number) from /home/users/userdir I.E cd home/users/userdir ll FSTR0001 Jul 8 14:20 FSTR0002 Jul 6 12:01 FSTR0003 May 25 09:45 FSTR0004 April 2 17:20 MSTR0034 Jul 6 12:45... (3 Replies)
Discussion started by: eurouno
3 Replies

8. Shell Programming and Scripting

Deleting files older than 7 days

Hi Guys, I want to delete folder/files older than 7 days. Im using the command below. find /test/test1 -mtime +7 -print0 | xargs -0 rm -Rf /test/test1/* which works ok, but it deletes the test1 folder as well which i dont want. The test1 folder will have a list of sub-folders which in... (4 Replies)
Discussion started by: shezam
4 Replies

9. Shell Programming and Scripting

Script for deleting 30 days older

Hi, I need a script to delete files that are 30 days older and also the file name should contain aa or ab or ac as substring... Regards, Dolly.... (3 Replies)
Discussion started by: moon_friend
3 Replies

10. Shell Programming and Scripting

Deleting / finding files older than X days missess a day

Hi When trying to find and delete files which are, say, 1 day, the find command misses a day. Please refer the following example. xxxd$ find . -type f -ctime +1 -exec ls -ltr {} \; total 64 -rw-rw-r-- 1 oracle xxxd 81 Apr 30 11:25 ./ful_cfg_tmp_20080429_7.dat -rw-rw-r-- 1... (4 Replies)
Discussion started by: guruparan18
4 Replies
Login or Register to Ask a Question