command to find most recent file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers command to find most recent file
# 1  
Old 03-11-2010
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 command to search my data:

find /x/y/z -type f -name data -exec grep "help" {} +

It works, but how can I search for the word "help" in the most recent files "data".
I try with the command "-newer" but it did not work Smilie

Please, can somebody help me?

Thanks
# 2  
Old 03-11-2010
you can get the most recent files by doing

Code:
ls -lart /some/directory/name/

so maybe try something like

Code:
ls -lart /some/directory/name/ | find -some -fancy -find -flags

# 3  
Old 03-12-2010
Thanks for your answer, but I don't know how to use this code:

Code:
ls -lart /some/directory/name/ | find -some -fancy -find -flags

with this one:

Code:
find /x/y/z -type f -name data -exec grep  "help" {} +

# 4  
Old 03-12-2010
Code:
 find -mtime <some time> -exec grep "help" {} \;


Last edited by murugaperumal; 03-12-2010 at 06:05 AM..
# 5  
Old 03-12-2010
You can, to a certain degree, limit the search space with the -mtime option. Eg '-mtime -1' would mean files modified during the last 24 hours. With -newer you'd have to have a reference file that times could be compared against. Such a file can be created using touch and an appropriate timestamp.
# 6  
Old 03-12-2010
Thanks for the answers, I think mtime is not a solution for my case, since I write a script for general cases, so I think -newer has to be the solution.
Concerning the touch command, this is a nice idea, but how can I use the find command to find every files I need, and then using touch to gather all my files?
# 7  
Old 03-12-2010
This is for example.If you want to execute some command for the matched files.You try this.
Code:
 find -type f -exec touch {} \;

 
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. Shell Programming and Scripting

FTP command to get most recent file

Hello Experts... dir of FTP will list all the files in the directory. Is there any command or option of dir that will give me the most recent file only? Since I couldn't find any such thing, I thought of creating a log file (of FTP results) and work on this log file to determine the most recent... (2 Replies)
Discussion started by: juzz4fun
2 Replies

4. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

5. Shell Programming and Scripting

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: find . -name "exp_prod_*_*_yes_*_.log" -exec ls -ltr {} \;... (12 Replies)
Discussion started by: nir_s
12 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

7. UNIX for Advanced & Expert Users

vi recent command history

How do you get your recent vi command history to show up? I keep randomly getting like my previous 5 commands and can't figure out how I'm doing it. I think it has something to do with the shift key and another button. (6 Replies)
Discussion started by: cokedude
6 Replies

8. 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

9. 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

10. Linux

tail most recent file command

I have only been working with Linux for a few years now so bear with my noob question. I was wondering if there is a way to tail the most recent file that has a file name like 'scrubsncoa%'. There will be at least 2 files in the directory that start with 'scrubsncoa' and a few other different... (2 Replies)
Discussion started by: RyanD
2 Replies
Login or Register to Ask a Question