getting the most recent file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting the most recent file
# 1  
Old 06-22-2006
getting the most recent file

Hi,
I have files coming in every day with that days timestamp like:
nameyyyymmddhhmmss.ext.
I need the most recent one and so i am using

cat `ls -t name*|head -1 ` > temp

i am sorting the files in the decending order and am copying the most recent one into a temp file.
It works at times but sometimes it does not.
Is there a better way to do it?
I dont want to compare it to todays absolute date ;I just want the most recent file.
any suggestions will be appreciated.
thanks
# 2  
Old 06-22-2006
Code:
ls -1 * | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*/\1 &/' | sort -n | cut -d ' ' -f2- | tail -1


Last edited by vgersh99; 06-22-2006 at 04:03 PM..
# 3  
Old 06-22-2006
Can you explain the
[^0-9]*\([0-9][0-9]*\).*/\1 &/'
part?
thanks
# 4  
Old 06-22-2006
Quote:
Originally Posted by anujairaj
Can you explain the
[^0-9]*\([0-9][0-9]*\).*/\1 &/'
part?
thanks
1. anything BUT the numberS followed by
2. any number of digits followed by
3 anything

output 'bullet item '2' followed by ' ' and followed by the entire string
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. 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

3. Solaris

Recent file available

Dear, Require a script to check : If the file under /opt/OV/log directory has recent 5 hours(or user defined value) file generated or not If generated then cmd to call : opcmsg a=a o=o msg_grp=OpC msg_text="Log file didn't generated on $time" s=critical (1 Reply)
Discussion started by: mjoshi87
1 Replies

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

5. Shell Programming and Scripting

how to get the most recent file that contains a specific string

Hi All, I wish to get the most recent file from a dir which contains a specific string. for example, in a dir sample/ , i have 3 files file1.txt -- contains 'good' file2.txt -- contains 'good' file3.txt-- contans 'hello' I want to search for the recent file (that is file2.txt) which... (3 Replies)
Discussion started by: little_wonder
3 Replies

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

7. Shell Programming and Scripting

Getting the most recent file

Hi people, Please some help over here. I have logs in a directory, in which I need to get the most recent file in order to put it within other command. The format of the files are loadfiles20090308094339_41 loadfiles20090308094418_42 loadfiles20090308095457_43... (4 Replies)
Discussion started by: cgkmal
4 Replies

8. AIX

Changing name of most recent file

I need to change the name of a file within a script. For example I have two files. The first named scrnslc_0001 and the second scrnslc_0002. I want to change the name of the second to scrnslc_out. The appended number will change, and I won't know the file name in advance. If there were only one... (1 Reply)
Discussion started by: warpmail
1 Replies

9. UNIX for Dummies Questions & Answers

reading directory for most recent file?

Dear All, I'm trying to write a script that searches thru a directory looking for a most recent file and then scp that file. I have the scp working, but I don't know how to browse the directory and select the most recent file. The file name includes a date & time stamp (e.g.... (3 Replies)
Discussion started by: duncan_glover
3 Replies

10. Shell Programming and Scripting

Most Recent File script

OK, I know next to nothing about scripting in unix, and at the moment I don't have access to a unix environment... We have an application that generates a text report file which is later printed. The format is this: bbtptcYYMMDDSSCC.txt (year/month/day/second/check digit) I want a... (1 Reply)
Discussion started by: josborn777
1 Replies
Login or Register to Ask a Question