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
[Urgent]how to print the file names into a txt file??? kumarsaravana_s Shell Programming and Scripting 15 03-11-2007 11:32 PM
Reducing file names paul1s UNIX for Dummies Questions & Answers 5 10-12-2006 04:54 AM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 01:25 AM
File names giantflameeater UNIX for Dummies Questions & Answers 9 11-24-2004 03:03 PM
Getting all file names in a folder. adadevil UNIX for Dummies Questions & Answers 5 06-28-2001 01:30 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-10-2005
Registered User
 

Join Date: Sep 2005
Posts: 38
Stumble this Post!
To get the file names.

Hi,
I have written a shell script which selects the particular type of file (consider that .xml files) from each sub directories under a parent directory and does some manipulation. Now what happens here at a time it looks for asingle sub directory only. I mean it is executed recursively for each sub directory. Now my intent is to select all the .xml files from all subdirectories and to do some manipulation on the oldest file among all files. How it can be done?

what I did :
I selected all the files from each directory and redirected to them a flat file using command:
ls -lurt $dir/*.xml | awk '{print $6,$7,$8,$9}'>> tmp.txt.
from tmp.txt I can find the file name with full path using the command:
cut -d' ' -f4 tmp.txt
Now I faced difficult to sort the files which are in tmp.txt file.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-10-2005
Registered User
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
Stumble this Post!
Using GNU tools you can do:

numfiles=10 #number to process
find $dir -name "*.xml" -printf "%T@\t%p\n" |
sort -k1,1n |
tail -$numfiles |
cut -f2- |
while read file; do
echo processing $file
done

For comparison have a look at:
http://www.pixelbeat.org/scripts/newest
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0