Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting 2 week old files unix

Status
Not open for further replies.

pavikavi

Programmer
Oct 28, 2003
8
US
hi

How can i delete a file from the directory which is 2 weeks old from the current date using the shell script
and this script will be assigned to the crontab so date calculation should be dynamically done.

Please help me out.

thanks
pavithra
 
man find

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Or do a keyword search on this forum for &quot;delete old&quot;.

You'll come up with about 11 topics dealing with deleting files that are a certain age.

Check out this reply: thread822-571368
 
i need a script whihc loops thru all the files in a folder and checks out its timestamp and compare it with current date of the system and delete those files which are 2 weeks old or more
 
Do a
Code:
 man find
and take a look at the -mtime and -exec options. A
Code:
 man xargs
could also be of interest.

Hope This Help
PH.
 
OK. I'll read the thread for you:

find /your_directory_AKA_&quot;folder&quot; -mtime +14 -print | xargs rm -f
 
thanks a lot people, its really a great help from all of you

pavithra
 
but you also can use:

find /your_directory_AKA_&quot;folder&quot; -mtime +14 -exec rm{} ;

this derives the results directly to rm.
in some unix the semikolon needs a blank between the closing bracket and semikolon, in others not.

hth
Uwe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top