The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File Modified : Alert me StrengthThaDon UNIX for Dummies Questions & Answers 6 04-08-2008 03:23 PM
how to retrieve original contents of a modified file (modified using vi) novice100 UNIX for Dummies Questions & Answers 3 05-31-2007 08:50 PM
who modified my file!! mohanprabu UNIX for Dummies Questions & Answers 4 10-28-2005 10:18 PM
File last modified szzz High Level Programming 4 11-05-2003 11:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-15-2008
m69w m69w is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
Last modified file in 2 or more directories

Hi,

Is there any simple way to get the last modified file in a set of 2 or more directories? This should return one file only (not 1 file per directory)

Thanks for your help
  #2 (permalink)  
Old 07-15-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Code:
ls -drt /dir1/* /dir2/* | tail -1
  #3 (permalink)  
Old 07-16-2008
m69w m69w is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
Thanks Annihilanic. Would you know how to circumvent the ls: Arg list too long problem ?
  #4 (permalink)  
Old 07-16-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
I'm presuming there are no subdirectories. It becomes difficult with large numbers of files because you need to use multiple ls commands, therefore you can no longer use its built-in sort-by-time capability. Instead you have to it yourself. This is a little easier if you can be sure that you are only interested in files that were modified in the last 12 months, so you can ignore files whose dates contain a year, e.g.

Code:
find dir1 dir2 -type f | xargs ls -l | awk '$8 ~ /:/' | sort -k 6,6M -k 7,7n | tail -1 | awk '{print $NF}'
Also hopefully your version of sort supports the M sort key (i.e. months), otherwise you have to fiddle some more.

Last edited by Annihilannic; 07-16-2008 at 04:23 AM.. Reason: forgot the tail bit
  #5 (permalink)  
Old 07-16-2008
m69w m69w is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
This is good enough for me, at leat it works with my setup. Thanks again
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0