Search for a recently updated file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for a recently updated file
# 1  
Old 09-26-2011
Search for a recently updated file

Hi,

I am looking for a command to search for a specific file which was recently modified in the current directory leaving some unwanted files to be listed.

For example, when I try
HTML Code:
ls - lrt
it shows the following output.

[HTML
-rw-rw-r-- 1 repdev pcenter 1593 Sep 26 09:08 2_0.dat.idx
-rw-rw-r-- 1 repdev pcenter 979 Sep 26 09:08 2_0.dat
-rw-rw-r-- 1 repdev pcenter 1598 Sep 26 09:08 3_0.dat.idx
-rw-rw-r-- 1 repdev pcenter 2917 Sep 26 09:08 3_0.dat
-rw-rw-r-- 1 repdev pcenter 22046 Sep 26 09:44 5_resend_0.dat
-rw-rw-r-- 1 repdev pcenter 1116 Sep 26 09:44 13_resend_0.dat
-rw-rw-r-- 1 repdev pcenter 12592 Sep 26 10:04 1_0.dat
[/HTML]

I want to ommit the files with the name 'resend' and with .idx or any other extension except .dat extension and print the latest changed file from .dat extension.

In this case I want to print only the last entry of the above output

HTML Code:
-rw-rw-r--    1 repdev   pcenter       12592 Sep 26 10:04 1_0.dat
Thanks,
Sri
# 2  
Old 09-26-2011
Code:
 tail -1

will return the last entry (if that is always the correct one for you), otherwise you could pipe through grep first in order to discard unwanted entries prior to printing the last valid entry, eg.
Code:
ls -ltr | grep -v 'resend' | grep -E '\.dat$'|tail -1

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 09-26-2011
Code:
ls -lart *.dat|grep -v resend | tail -1

returns the listing in ascending time modified order of only files ending in .dat, removes anything containing resend in the line, and shows only the last line (the most recently modified)

however, if you have directories in there with an extension of .dat (unlikely) use the following.

Code:
ls -lart | grep -v resend | grep .dat$ |tail -1

This User Gave Thanks to Tommyk For This Post:
# 4  
Old 09-26-2011
WOW.. It works.

Thanks a ton.

Sri
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Updated Forum Search Index Min Word Length to 2 Chars and Added Quick Search Bar

Today I changed the forum mysql database to permit 2 letter searches: ft_min_word_len=2 I rebuilt the mysql search indexes as well. Then, I added a "quick search bar" at the top of each page. I have tested this and two letter searches are working; but it's not perfect,... (1 Reply)
Discussion started by: Neo
1 Replies

2. What is on Your Mind?

Updated Forum Search Index Min Word Length (Again)

For some reason, three char word lengths were not showing up in search results, even though the minimum is set to three and has been for a long time. After monkeying around with this, I turned off full page search, dumped all search indexes, and re-enabled full text search and it's working... (1 Reply)
Discussion started by: Neo
1 Replies

3. Shell Programming and Scripting

Log search and mail it if the log is updated before 24 hours from the current time

Hi , We have around 22 logs , each has different entries. I have to automate this using shell script. The ideas which am sharing is given below 1) We use only TAIL -100 <location and name of the log> Command to check the logs. 2) We want to check whether the log was updated before 24... (13 Replies)
Discussion started by: Kalaihari
13 Replies

4. Shell Programming and Scripting

How to read a file name that was recently edited when listed using ls command?

I was trying to write a script that will process recently creatd file. From below, the script should process input_20111230.dat file. sam:/top/work/data/input: ls -ltr input_*.dat -rw-rw-rw- 1 work edprod 455668 Dec 24 09:16 input_20111224.dat -rw-r--r-- 1 work edprod ... (7 Replies)
Discussion started by: siteregsam
7 Replies

5. Shell Programming and Scripting

Putting two perl scripts together... triming whitespace off of recently parsed file

Thanks to people's help, I have composed a single line within a .sh script that Ports a file into a csv: perl -p -i -e... (5 Replies)
Discussion started by: Astrocloud
5 Replies

6. Shell Programming and Scripting

Find user owner of the most recently file in the system

Good evening everybody, I have to find the user owner of the most recently file in the system How can I do? :confused: (5 Replies)
Discussion started by: Guccio
5 Replies

7. Shell Programming and Scripting

find recently modified/ updated file

hi gurus, i would like to know how can i find logs files which were recently modified or updated? :confused: using this command? find . -name "*.log" -mtime ?? so what should i put for mtime? thanks. wee (9 Replies)
Discussion started by: lweegp
9 Replies

8. Shell Programming and Scripting

Find recently updated files in home directory

Is there a shell command that will allow me to list index files in the /home directory for all users on a server that have been updated within the past 24 hours? (e.g. index.htm .html .php in/home/user1/public_html /home/user2/public_html /home/user3/public_html etc ) (2 Replies)
Discussion started by: Kain
2 Replies

9. UNIX for Dummies Questions & Answers

recently updated files

How do I find files those have been updated in the last 24 hours, sort them by size descending and then display the top of the long list? (6 Replies)
Discussion started by: shantanuo
6 Replies

10. Shell Programming and Scripting

ftp most recently modified file

Hi what is the most optimum way to ftp the most recently modified file starting with a particular string. i tried this ftp -n 2>logfile 1>&2 <<EOF open xxxxxx user xxxx xxxx prompt ls -ltr f* res !var=`tail -1 |awk { print $9 }'` bye EOF that gives... (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies
Login or Register to Ask a Question