LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-12-2010, 01:29 PM   #1
ddenton
Member
 
Registered: May 2007
Posts: 114

Rep: Reputation: 15
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?

Thanks!

Dan
 
Old 08-12-2010, 01:36 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
You might like the `stat` command:
Code:
# 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
sasha@reactor:
 
1 members found this post helpful.
Old 08-12-2010, 01:37 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

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.
 
1 members found this post helpful.
Old 08-12-2010, 02:57 PM   #4
ddenton
Member
 
Registered: May 2007
Posts: 114

Original Poster
Rep: Reputation: 15
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!
 
  


Reply

Tags
mtime


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mtime option in find command ahmedb72 Linux - Newbie 7 06-23-2009 09:48 AM
alternative command for "find -mtime " sspisharody Linux - Newbie 2 02-13-2009 04:41 PM
using find to compare file mtime with another file's mtime TheFueley Linux - Newbie 1 12-23-2008 08:06 PM
'find' gives different results when using -mtime with -print vs -exec BrianK Linux - General 1 12-08-2008 10:32 AM
mtime in find vs ls lslade Linux - Software 0 11-17-2005 01:06 PM


All times are GMT -5. The time now is 02:13 AM.

Main Menu
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