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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-09-2007
Registered User
 

Join Date: Sep 2006
Posts: 30
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
Reply With Quote
Forum Sponsor
  #2  
Old 12-09-2007
Registered User
 

Join Date: Sep 2006
Posts: 30
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
Reply With Quote
  #3  
Old 12-10-2007
Moderator
 

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

Regards
Reply With Quote
  #4  
Old 12-10-2007
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
Reply With Quote
  #5  
Old 12-10-2007
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.
Reply With Quote
  #6  
Old 12-10-2007
Moderator
 

Join Date: Feb 2007
Posts: 2,329
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0