Unix/Linux Go Back    


OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

Arrange file by modified date

OS X (Apple)


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-10-2017   -   Original Discussion by gigagigosu
gigagigosu's Unix or Linux Image
gigagigosu gigagigosu is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 10 February 2017, 3:08 PM EST
Posts: 31
Thanks: 17
Thanked 0 Times in 0 Posts
Arrange files by modified date

Hi,

Am performing a find based on filename and result can contain multiple files being found
Let's say my find command is


Code:
find /Archive -f -name 12345.pdf

and result of find command is


Code:
/Archive/Folder A/12345.pdf
/Archive/Folder B/12345.pdf

please note white space in folder names

I need to get the file that has most recent modified date


Moderator's Comments:
Arrange file by modified date Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-10-2017 at 02:39 PM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 02-10-2017   -   Original Discussion by gigagigosu
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 13 June 2018, 6:37 PM EDT
Location: Saskatchewan
Posts: 22,696
Thanks: 1,183
Thanked 4,334 Times in 3,995 Posts


Code:
find /Archive -f -name 12345.pdf -printf "%T@ %p\n" | sort -rn | head -n 1

This will prepend a date in epoch seconds to every file name, which sort can order by time.

Last edited by Corona688; 02-10-2017 at 02:03 PM.. Reason: mtime, not atime
The Following User Says Thank You to Corona688 For This Useful Post:
gigagigosu (02-10-2017)
Sponsored Links
    #3  
Old Unix and Linux 02-10-2017   -   Original Discussion by gigagigosu
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 13 June 2018, 6:37 PM EDT
Location: Saskatchewan
Posts: 22,696
Thanks: 1,183
Thanked 4,334 Times in 3,995 Posts
A version using awk:



Code:
find /Archive -f -name 12345.pdf -printf "%T@ %p\n" | awk '$1 > P { P=$0 } ; END { $0=P ; $1=""; print substr($0,2) }'

The Following User Says Thank You to Corona688 For This Useful Post:
gigagigosu (02-10-2017)
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I display a file's last modified date? mattadams1983 AIX 4 10-27-2016 05:02 AM
current date modified file guddu_12 Shell Programming and Scripting 7 08-01-2012 11:55 AM
Test if a file has a last modified date of within the last 24 hours rethink Shell Programming and Scripting 2 03-17-2011 05:04 AM
Finding the modified date time of a file JamesJoe UNIX for Advanced & Expert Users 2 01-30-2011 02:27 PM
How do I get the last modified date of a file? akpopa UNIX for Dummies Questions & Answers 2 08-29-2001 03:08 PM



All times are GMT -4. The time now is 04:08 PM.