![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare date from db2 table to yesterday's Unix system date | sasaliasim | Shell Programming and Scripting | 8 | 04-24-2008 03:04 AM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 12:01 PM |
| parsing a system log file via the 'date' command | cjones | Shell Programming and Scripting | 5 | 05-10-2007 09:26 AM |
| Changing Creation Date to a Prespecified Date of a File In Unix | monkfan | UNIX for Dummies Questions & Answers | 4 | 11-28-2006 03:15 AM |
| need to create a file with its name having system date | hamsa | Shell Programming and Scripting | 11 | 10-18-2006 01:48 AM |
|
|
LinkBack | Thread Tools | Display Modes |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
||||
|
ctime
You can also use:
find /search/path -mtime +30 | xargs rm -i ctime indicates inode data change: ie. when you do chmod. chown on the file or when the file size changes. Not the contents of the file.
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com 'True strength lies in gentleness' - Irish proverb |
|
||||
|
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. |
|
||||
|
Q
Mmm, let's picture this: you change exactly 1 character in an ASCII text file, thus not changing the file size. Does this change the ctime as well? I always thought not?
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com 'True strength lies in gentleness' - Irish proverb |
||||
| Google UNIX.COM |