![]() |
|
|
|
|
|||||||
| Tips and Tutorials Helpful articles from our Users. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to find ot ctime , mtime ,atime | nilesrex | Shell Programming and Scripting | 4 | 08-10-2006 07:51 AM |
| atime, ctime, mtime somewhere along csize.. | moxxx68 | UNIX for Dummies Questions & Answers | 4 | 03-02-2005 02:14 PM |
| mtime vs ctime | moxxx68 | UNIX for Dummies Questions & Answers | 3 | 11-06-2004 06:57 PM |
| Converting regular time to CTIME | PGPhantom | UNIX for Dummies Questions & Answers | 9 | 08-23-2002 06:47 PM |
| ctime & find | 98_1LE | UNIX for Dummies Questions & Answers | 1 | 06-22-2001 12:33 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
| Forum Sponsor | ||
|
|
|
||||
|
find command -mtime -ctime -atime
The find command uses arguments like:
-mtime -2 -mtime +2 -mtime 2 There are -ctime and -atime options as well. Since we now understand the differences among mtime, ctime, and atime, by understanding how find uses the -mtime option, the other two become understood as well. So I will describe find's use of the -mtime option. As you probably know, the find command can run for minutes or hours depending on the size of the filesystem being searched. The find command makes a note of its own start time. It then looks at a file's mtime and computes how many seconds ago the file was modified. By dividing the seconds by 86,400 (and discarding any remainder), it can calculate the file's age in days: Code:
0 days in seconds: 0 - 86399 1 day in seconds: 86400 - 172799 2 days in seconds: 172800 - 259159 "-mtime -2" means files that are less than 2 days old, such as a file that is 0 or 1 days old. "-mtime +2" means files that are more than 2 days old... {3, 4, 5, ...} It may seem odd, but +0 is supposed to work and would mean files more than 0 days old. It is very important to recognize that find's concept of a "day" has nothing to do with midnight. Last edited by Perderabo; 08-05-2007 at 08:40 AM. |
|
||||
|
Using perl to display the file timestamps
The ls program will display mtime if you use "ls -l". And you can get atime or ctime with "ls -lu" or "ls -lc". But ls uses a strange format. It displays the month and day in all cases. If the timestamp is recent, it also displays hour and minute. If the timestamp is older than 6 months, it display the year instead of hour and minute. A clever script can reformat this to year, month, day, hour, and minute. But ls will not display the seconds. The gnu version of ls (which is usually the only version on linux) does have extended options like --fulltime. But these extended options are non-standard and won't be available on other versions of Unix.
The perl language is also non-standard, but perl tends to be available on most versions of unix. For example, a version of perl is supplied with HP-UX and Solaris. Perl can easily display the timestamps of files. Here are some perl one-liners to display atime, mtime, and ctime. Code:
$ echo hello > testfile ; date Thu Aug 30 08:31:57 EDT 2007 $ chmod 700 testfile ; date Thu Aug 30 08:32:48 EDT 2007 $ cat testfile ; date hello Thu Aug 30 08:33:30 EDT 2007 $ $ $ $ $ perl -e '@d=localtime ((stat(shift))[8]); printf "%4d%02d%02d%02d%02d%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]' testfile 20070830083330 $ perl -e '@d=localtime ((stat(shift))[9]); printf "%4d%02d%02d%02d%02d%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]' testfile 20070830083157 $ perl -e '@d=localtime ((stat(shift))[10]); printf "%4d%02d%02d%02d%02d%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]' testfile 20070830083248 $ |
||||
| Google UNIX.COM |