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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to remove files

Status
Not open for further replies.

pranesh11

Technical User
Dec 4, 2003
50
0
0
IN

Hi,

I am looking for a script or command to remove all files which are older than 7 days. In my linux box under /home there are many user directories i need to delete all the files which r older than 7 days.. how do i do it??.. i tried find /home/*.ext -atime +7 -print | xargs rm .. i dunno its correct or not.. but in this i hv mentioned *.ext, i don't want to mention any extension.. it should delete all the files with and without extension and it should not delete any directories.. only file removal is needed.. can anybody help me plz. Thanks
 
Try this
[tt]
find /home -type f -mtime +7 -print | xargs rm
[/tt]

Jean Pierre.
 
Careful. This will also delete users' .profile and any other . files, which will probably be important and have an mtime > 7 days!
 
Exact, that is not a good thing.
If you want to preserve files with name starting with dot :
[tt]
find /home -type f ! -name '.*' -mtime +7 -print | xargs rm
[/tt]

Jean Pierre.
 
Agreed, but you might also consider things like user-written scripts and/or menus which are required on logging in. It's a bit of a minefield and I'd suggest the *.extension method as being the safest option. You can, of course, have consecutive such finds in a script for this purpose. HTH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top