-   Linux - General (
-   -   Command to find only mtime (

ddenton 08-12-2010 02:29 PM

Command to find only mtime
Hello all...

I've got a script where I have to parse out the last modified time for a large amount of files.

Piping the output for "ls" into "cut" seems to work most of the time, but the output is unpredictable. The "fields" argument doesn't find the date modified columns consistently, and using character count is as well since the output can vary in width depending on the file name.

Is there a command that specifically displays the mtime of a file?



GrapefruiTgirl 08-12-2010 02:36 PM

You might like the `stat` command:

# use %y to get "last modified":
sasha@reactor: stat --printf '%y\n' filename
2010-07-28 21:43:39.442558580 -0300

# show full normal `stat` output:
sasha@reactor: stat filename
  File: `filename'
  Size: 913            Blocks: 8          IO Block: 4096  regular file
Device: 30ch/780d      Inode: 408338      Links: 1
Access: (0644/-rw-r--r--)  Uid: (  501/  sasha)  Gid: (  100/  users)
Access: 2010-07-28 21:43:39.442558580 -0300
Modify: 2010-07-28 21:43:39.442558580 -0300
Change: 2010-07-28 21:43:39.442558580 -0300

druuna 08-12-2010 02:37 PM


You can change the way the date/time field is displayed to make it consistent:

ls -ltc --time-style=long-iso

See the ls man page for details and other styles.

Hope this helps.

ddenton 08-12-2010 03:57 PM

Thanks to both for replying! The stat command seems to work best for my needs. I don't have much control over the format, but my dependence on "cut" parsing the output is lessened because I have less fields to work with.

Thanks again!

All times are GMT -5. The time now is 06:24 AM.