The UNIX and Linux Forums  


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
find command in while loop - how to get control when no files found? mavsman Shell Programming and Scripting 3 04-03-2008 12:44 PM
getting error 0403-016 Cannot find or open the file while reading a long line karthee Shell Programming and Scripting 2 06-05-2005 01:00 AM
ls -l output with long iso format rofflox Shell Programming and Scripting 1 04-16-2004 10:46 AM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 06:38 PM
solaris2.6 command to find/list system configuration subhransu UNIX for Dummies Questions & Answers 4 05-01-2001 02:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-09-2007
alexcol alexcol is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Help with find command and list in a long format each found file

The purpose of those comands are to find the newest file in a directory acvrdind to system date, and it has to be recursively found in each directory.
The problem is that i want to list in a long format every found file, but the commands i use produce unexpected results ,so the output lists in a long format the files located in the path working directory.
ie
i tried 2 ways but not working
1. touch -t YYYYMMDD filename. ok
2. find -newer filename -exec ls -lrt ´{} \; · It doesn work

the second trial i used is:
find -newer filename > anotherfile
while read ine
do
ls -lrt "$line"
done < another file

In the above examples keeps listing files located in the path working directory not the desired files (The newest one en each directory)
Why this happens?
id appreciate any help and your support gurus.
Thanks
ie output
  #2 (permalink)  
Old 12-10-2007
alexcol alexcol is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Smile Help in finding the newest file for each directory (Recursively)

finding out the problem ive got part of the solutionin this way:

find /bmd -type f -newer $anio$mes$dia$hora$minuto -exec ls -lrtd {} \;

(previously definig the variables
Output
-rw-r----- 1 ftp_coll ict 3251584 Dec 9 23:30 /bmd/boboprd/input/BOBOBSC25480920071209233010000.intec
-rw-r----- 1 ftp_coll ict 2518526 Dec 9 23:49 /bmd/boboprd/input/BOBOBSC25481020071209234956000.intec
-rw-r----- 1 ftp_coll ict 454771 Dec 10 00:00 /bmd/boboprd/BOBOBSC25481120071210000004000.intec
-rw-r----- 1 ftp_coll ict 2324852 Dec 10 00:30 /bmd/boboprd/BOBOBSC25481220071210003007000.intec
-rw-r----- 1 ftp_coll ict 2316639 Dec 9 23:23 /bmd/prod/input/ICTBSC36654520071209232300000.intec
-rw-r----- 1 ftp_coll ict 2871303 Dec 9 23:38 /bmd/prod/input/ICTBSC36654620071209233800000.intec
-rw-r----- 1 ftp_coll ict 1730269 Dec 9 23:53 /bmd/prod/input/ICTBSC36654720071209235301000.intec
but i want the output list just one file (the newest one) for each directory

i woul be grateful to any help. Thanks
  #3 (permalink)  
Old 12-10-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
Check the file you touched, does it have the the expected date?

Regards
  #4 (permalink)  
Old 12-10-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
You can get the newest file in a dir with:-

ls -lt | head -1
  #5 (permalink)  
Old 12-10-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
A further thought - if you are interested in newest file in a directory but wanteing to recurse also:-

find /BMD -type d -exec ls -lt | head -1 {}\;

Only thing is I am not *sure* the pipe will work ok within the -exec construct.
  #6 (permalink)  
Old 12-10-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
ajcannon ,

The question is to search for files newer than a reference file created with touch. It seems that the created file with touch don't have the expected created date. The touch command is not used properly, it should be:


Code:
touch -t [CC]YYMMDDhhmm[ss] filename

or:

Code:
touch -t [CC]YYMMDDhhmm[ss] filename

The century and the seconds are optional.

Regards
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 06:14 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