Home
Man
Search
Today's Posts
Register

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

Arrange file by modified date

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 02-10-2017
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 03:39 PM.. Reason: Added CODE tags.
# 2  
Old 02-10-2017
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 03:03 PM.. Reason: mtime, not atime
The Following User Says Thank You to Corona688 For This Useful Post:
gigagigosu (02-10-2017)
# 3  
Old 02-10-2017
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)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:02 AM
Script to copy creation date over top of modified date? toysareforboys Shell Programming and Scripting 3 04-14-2016 10:48 AM
Find file by filename or with newest modified date finn Shell Programming and Scripting 4 06-03-2015 03:22 AM
current date modified file guddu_12 Shell Programming and Scripting 7 08-01-2012 12:55 PM
Test if a file has a last modified date of within the last 24 hours rethink Shell Programming and Scripting 2 03-17-2011 06:04 AM
Finding the modified date time of a file JamesJoe UNIX for Advanced & Expert Users 2 01-30-2011 03:27 PM
Finding modified File List after the chosen date in Korne Shell... marconi Shell Programming and Scripting 2 01-22-2008 05:27 AM
how to retrieve original contents of a modified file (modified using vi) novice100 UNIX for Dummies Questions & Answers 3 05-31-2007 09:50 PM
Arrange date in a field sabercats Shell Programming and Scripting 6 02-28-2006 04:56 PM
How do I get the last modified date of a file? akpopa UNIX for Dummies Questions & Answers 2 08-29-2001 04:08 PM


All times are GMT -4. The time now is 09:49 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password