LinuxQuestions.org
Help answer threads with 0 replies.
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, 10: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, 10:28 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Use the find cmd: http://www.computerhope.com/unix/ufind.htm
 
Old 05-23-2006, 10: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: 328Reputation: 328Reputation: 328Reputation: 328
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, 01: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, 03:06 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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, 03:21 AM   #6
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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, 04: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


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
How to calculate file age ? "File xy is 2 days 3 hours old" fluppi Linux - Software 5 06-03-2013 11:27 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
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 03:46 AM
How to delete pass 30 days email linuxalliance Linux - Networking 3 04-04-2002 08:34 PM


All times are GMT -5. The time now is 05:39 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration