To find the latest modified file in a directory | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

To find the latest modified file in a directory

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-30-2013
Sree10 Sree10 is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 4 December 2013, 10:13 PM EST
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
To find the latest modified file in a directory

I am trying to fetch the latest modified file from a directory using the command
find . -type f -exec ls -lt \{\} \+ | head | awk '{print $9}'

After the O/P, I get the below mentioned error and the command doesnt terminate at all.

find: ls terminated by signal 13
find: ls terminated by signal 13
find: ls terminated by signal 13
find: ls terminated by signal 13

Please can you let me know how this can be rectified.

Thanks!
Sponsored Links
    #2  
Old 10-30-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 26 November 2014, 7:23 AM EST
Location: Aachen, Germany
Posts: 4,703
Thanks: 80
Thanked 1,169 Times in 1,099 Posts
That pipe doesn't cause any problem on my linux. What be your system?
Sponsored Links
    #3  
Old 10-30-2013
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by Sree10 View Post
I am trying to fetch the latest modified file from a directory using the command
find . -type f -exec ls -lt \{\} \+ | head | awk '{print $9}'
To print the name of the last modified file in a directory, you don't need find nor awk :

Code:
ls -t | head -n1

Regards,
Alister
Sponsored Links
Closed 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
Help with finding the latest modified version of a file within directories co21ss Shell Programming and Scripting 6 12-13-2012 04:47 PM
to pick the latest file modified in a directory vishwakar Shell Programming and Scripting 5 07-08-2011 12:20 AM
How to get the latest modified file name in /home directory? crest.boy UNIX for Dummies Questions & Answers 3 03-12-2010 05:31 AM
How to find the latest modified file from the unix server. sreenu80 Shell Programming and Scripting 2 10-16-2009 06:40 AM
perl find directory only if modified in last hour frustrated1 Shell Programming and Scripting 0 10-12-2007 05:50 PM



All times are GMT -4. The time now is 01:19 PM.