LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2009, 01:16 PM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

Rep: Reputation: 48
Delete old files older than 7 days


find -type f /path/* -mtime +7 -exec rm {} \;

Is this the best way to delete only files (not directories) within /path that are older than 7 days? or is there a better way?
 
Old 09-18-2009, 01:30 PM   #2
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,275

Rep: Reputation: 148Reputation: 148
Yess the "f" denote regular files
 
Old 09-18-2009, 01:32 PM   #3
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

Original Poster
Rep: Reputation: 48
Thanks. and if i ever wanted to change it to do files and non-empty directories, would i just remove the -type f, or does it get more complicated then that?
 
Old 09-18-2009, 02:15 PM   #4
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,697

Original Poster
Rep: Reputation: 48
Looks like I'd have to change the end to this instead.

-exec rm -rf {} \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 04:43 PM
Delete files older then 30 days stefaandk *BSD 1 01-07-2008 09:31 PM
script to auto delete files older than X days nocnoc Programming 17 12-06-2006 09:30 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 03:40 PM
delete files in server that is older than 30 days using cronjob latheesan *BSD 2 06-14-2005 01:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration