![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare date from db2 table to yesterday's Unix system date | sasaliasim | Shell Programming and Scripting | 9 | 12-01-2008 11:37 PM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 04:01 PM |
| parsing a system log file via the 'date' command | cjones | Shell Programming and Scripting | 5 | 05-10-2007 12:26 PM |
| Changing Creation Date to a Prespecified Date of a File In Unix | monkfan | UNIX for Dummies Questions & Answers | 4 | 11-28-2006 07:15 AM |
| need to create a file with its name having system date | hamsa | Shell Programming and Scripting | 11 | 10-18-2006 04:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
The find command with the mtime or ctime flags will do this for you:
find /search/path -mtime +30 -exec rm -i {} \; I put the -i flag here to prompt you for each file removed (linux defaults to this as I remember) - probably a better approach would be to copy them all to another directory and then only delete them once you are sure you want to get rid of them all. +30 in this examples indicates 30 days or older. You can put this all in your script. Regards. |
|
||||
|
I "man find" but do not understand.
May I know when we will use -ctime instead of -mtime? and why must put a ";" at last? I found if i just enter this command, it will also work: find /at/path/dir -mtime +3 |
|
|||||
|
I'd like to offer my thoughts on ctime verses mtime. Sorry, but this will be a little verbose.
First, if you change the contents of a file you change the mtime of a file. Since this is a change to the inode, ctime is updated as well. The mtime is bit like the date on a letter and ctime is a bit like the postmark on the envelope. You can set mtime to anything you want via the utime() system call or the touch command. Doing so sets the ctime and you cannot reset ctime. If you restored last year's payroll records from tape, you might want to set the mtime back to the end of last year. But the ctime will reliably still indicate when the last change to the file occurred. This is how your backup program will know that it must back up the file. The ctime is really used by backup program. But an application program that prints out a payroll listing would use mtime. |
![]() |
| Bookmarks |
| Tags |
| linux, mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|