LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-23-2006, 09:16 PM   #1
christina_rules
LQ Newbie
 
Registered: May 2006
Posts: 25

Rep: Reputation: 15
delete file more than 50 days


i need some help here

1. how can i delete file more than 50 days?

2. what is the difference between -ctime and -mtime?

thanks
 
Old 05-23-2006, 09:28 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Use the find cmd: http://www.computerhope.com/unix/ufind.htm
 
Old 05-23-2006, 09:34 PM   #3
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Code:
/usr/bin/find /somedir/ -daystart -mtime +50 -type f -exec /bin/rm -f {} \;
The above will delete files older than 50 days in directory '/somedir'.

The ctime is the last time the inode for a file (it's entry in the filesystem) was last changed. The mtime is when the file was last modified. You are almost always interested in the mtime.
 
Old 05-24-2006, 12:26 AM   #4
christina_rules
LQ Newbie
 
Registered: May 2006
Posts: 25

Original Poster
Rep: Reputation: 15
ok..but can i know why the below codes is needed?

Quote:
/usr/bin/
i mean can i just find . -daystart -mtime +50 -type f -exec rm{} \;?
 
Old 05-24-2006, 02:06 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
find is usually in /usr/bin, so as long as it's in your PATH var, you'll be fine using the short form.
For the paranoid, you always specify the full path in case someone's managed to hack your PATH var, which is also why root user dosn't have '.' ie current dir in PATH.
Actually (just checked), my normal user doesn't either....
 
Old 05-24-2006, 02:21 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
There are 3 types of timestamps in linux.
  • atime: the time a file was last accessed
  • mtime: the time the file was last modified
  • ctime: the time the inode was altered. This can happen by either changing permissions for a file or renaming it.
 
Old 05-24-2006, 03:13 AM   #7
christina_rules
LQ Newbie
 
Registered: May 2006
Posts: 25

Original Poster
Rep: Reputation: 15
i've created a file yesterday 23 may 2006 14:26 so to try chrism01's code but alter it to this:

find . -daystart -mtime +1 -type f -exec rm -f {} \;

but it doesn't work..the file still exists..how?

about explanation of the timestamps..thanks
 
  


Reply



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
How to calculate file age ? "File xy is 2 days 3 hours old" fluppi Linux - Software 5 06-03-2013 10:27 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 02:40 PM
delete files in server that is older than 30 days using cronjob latheesan *BSD 2 06-14-2005 12:37 PM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 02:46 AM
How to delete pass 30 days email linuxalliance Linux - Networking 3 04-04-2002 07:34 PM

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

All times are GMT -5. The time now is 07:48 AM.

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
Open Source Consulting | Domain Registration