How to find the recent file in many sub-directories?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find the recent file in many sub-directories?
# 1  
Old 06-14-2010
How to find the recent file in many sub-directories?

Hi guys,

Under my root directory there are many sub-directories which contains log file for every day of running.
How can I find , in one command only, the recent log file in each sub-directory?

For example, If I run the following:
Code:
find . -name "exp_prod_*_*_yes_*_.log" -exec ls -ltr {} \;

I'll get all the files . I need to cut from this list only the last file from each sub-directory.

Thanks in advance,
Nir
# 2  
Old 06-14-2010
did you try the -mtime -1 option on find?
# 3  
Old 06-15-2010
Yes, I did , but no data were retrieved.

---------- Post updated 06-15-10 at 01:02 PM ---------- Previous update was 06-14-10 at 02:55 PM ----------

I'll be glad to get more suggestions.

Thanks in advance,
Nir
# 4  
Old 06-15-2010
on /
Code:
find -P .  -name *.log  -mtime +1


Last edited by omerzzz; 06-15-2010 at 02:40 PM..
# 5  
Old 06-15-2010
Thanks , but the command has failed:

Code:
{oracle} /oa01 PROD> find -P . -name "*.log" -mtime +1
find: illegal option -- P
find: [-H | -L] path-list predicate-list

# 6  
Old 06-15-2010
lose the double quotation
worked for me in Ubuntu and red-hat.
Code:
uid=0(root) gid=0(root) groups=0(root)
root@omer-desktop:/# find -P . -name *.log
./tmp/vmware-root/appLoader-9051.log
./tmp/vmware-root/setup-9530.log
./tmp/vmware-root/appLoader-14811.log
./tmp/vmware-root/appLoader-7774.log
./tmp/vmware-root/setup-8038.log
./tmp/vmware-root/appLoader-8038.log
./tmp/vmware-root/appLoader-14819.log
./tmp/vmware-root/setup-7787.log
./tmp/vmware-root/setup-9051.log
./tmp/vmware-root/setup-8847.log
./tmp/vmware-root/setup-7774.log
./tmp/vmware-root/appLoader-7753.log
./tmp/vmware-root/setup-9933.log
./tmp/vmware-root/appLoader-7736.log
./tmp/vmware-root/appLoader-7757.log
./tmp/vmware-root/appLoader-7733.log
./tmp/vmware-root/appLoader-8041.log
./tmp/vmware-root/setup-8844.log

# 7  
Old 06-16-2010
Still fails Smilie
Probably "find -P" does not work on Solaris ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help script find file most recent

Hi, I need to find the most recent files by their name from an X repertoire. The problem is that the name of the files is of type: POWERL10_20151203000.xml POWERL10_20151203001.xml POWERL10_20151202000.xml FIXED VALUE_DATENNN.xml NNN = Sequential number I would need to recover the... (4 Replies)
Discussion started by: verita
4 Replies

2. UNIX for Dummies Questions & Answers

Find most recent file and copy to another directory.

Very new to shell scripting. Not sure if my title is correct but I will try and explain. Directory has 100+ files with this format, " ABCD_ABC_Abc_AB0126.abc ". When a new file gets created, the 16-19 characters in the file name gets incremented by 1. Ex...todays most recent file is... (14 Replies)
Discussion started by: askvip
14 Replies

3. UNIX for Dummies Questions & Answers

Getting directories resulted from Find in one file

Hi Need help for the following scenario. I am having two directories /tmp/a and /tmp/b. /tmp/a again has subdirectories /tmp/a/aa and /tmp/a/ab. I want to run a script from /tmp/b to search for a file user.lst in the folders /tmp/a/aa and /tmp/a/ab, if available, i want to make a file in... (3 Replies)
Discussion started by: sudeep.id
3 Replies

4. Shell Programming and Scripting

Find Directories That Do Not Contain A Certain File

I'm having problems figuring out the process to find directories that DO NOT contain a certain file. I have a mp3 collection that all the album art is name "folder.jpg". Not all the albums have images. I need a way to find the albums/directories that do not contain "folder.jpg". I can find the... (2 Replies)
Discussion started by: subsonic
2 Replies

5. Shell Programming and Scripting

find directories that do NOT contain a certain file extension

for x in `find /vmfs/volumes/v01tstn01a01/ -type d`; do find $x -name '*.vmx' > /dev/null || echo $x; done; The goal of this is to find the subdirectories that do NOT contain a file with the extension of .vmx Any help would be great! (6 Replies)
Discussion started by: hodnov
6 Replies

6. UNIX for Dummies Questions & Answers

command to find most recent file

Hi, Here is my problem: I try to write a script to find data in a file named "data" for exemple. Let's say I am in the directory /x/y/z, there are several sub-directories in the "z" directory (each sub-directory has a file "data") and I am searching for the word "help". So I use this... (9 Replies)
Discussion started by: StephB
9 Replies

7. Shell Programming and Scripting

find the most recent file containing a certain string

I want to find the most recent file containing ' NORESETLOGS" I'm already here but, how to sort this now in a correct way ? By the way, my version of find does not know about 'fprint' find . -type f -exec grep -i " NORESETLOGS" {} \; -exec ls -l {} \; | grep -vi " RESETLOGS" (5 Replies)
Discussion started by: plelie2
5 Replies

8. Shell Programming and Scripting

Find most recent files in dirs and tar them up?

Hey all.. This should be simple but stoopid here can't get head around it! I have many directories, say 100 each with many files inside. I need a script to traverse through the dirs, find most recent file in each dir and add it to a tar file. I can find the files with something like for... (1 Reply)
Discussion started by: bobdung
1 Replies

9. Shell Programming and Scripting

Find a file in sub-directories.. o/p just the path

Hello All, I am somehow stumped with this ting. 'Find' will sure show me.. but I want only thepath of all the occurences of the file in any of the sub-dirs.. Any help will be sincerely appreciated. thanx! (3 Replies)
Discussion started by: pranavagarwal
3 Replies

10. Programming

to find a file in set of directories

Hi, what is the command in unix to find a file abc.c in a directory which had n number of sub-directories. thanx (3 Replies)
Discussion started by: jazz
3 Replies
Login or Register to Ask a Question