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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 10-30-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 5 March 2015, 2:34 PM EST
Location: Aachen, Germany
Posts: 5,436
Thanks: 94
Thanked 1,417 Times in 1,334 Posts
That pipe doesn't cause any problem on my linux. What be your system?
Sponsored Links
    #3  
Old Unix and Linux 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 974 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 05:00 AM.