Selecting the file of latest Date

Thread Tools Search this Thread
# 1  
Error Selecting the file of latest Date

Hi Folks,
I have one query that there is a folder in which daily several logs files are getting created , I reached to that location through putty but what I observer that 10 files of different date are been created with same name , what I need to see is the latest file ...let say the location is

cd /var/logs

at this location I see ten different files of different date with same name say abc.log , I want to see the abc.log file of the latest date before opening it in Vi , please advise me the command that will filter out the latest abc.log file of latest date, so That I can open the latest file through Vi editor
# 2  
You can't have ten files with the same name in a directory. Is the date embedded in the filename? If so, best is in the format YYYYMMDDHHmm, then the files will display already sorted.

vi $(tail -1 <(ls))

vi $(head -1 <(ls -t))

This User Gave Thanks to Scott For This Post:
# 3  
Originally Posted by Scott
You can't have ten files with the same name in a directory. Is the date embedded in the filename? If so, best is in the format YYYYMMDDHHmm, then the files will display already sorted.

vi $(tail -1 <(ls))

vi $(head -1 <(ls -t))

Yeah scott , files are created with date is also embedded with them let say,
HTML Code:
so please advise I want to open the latest one through Vi editor abc20120517abc.log file
# 4  
vi $(tail -1 <(ls abc*.log))

Or if <(..) doesn't work
vi $(ls abc*.log | tail -1)

set -- abc*.log
vi $(eval echo \${$#})

# 5  
you will get the latest file name : ls -lrt | tail -1then vi it.

Last edited by Scott; 05-19-2012 at 12:35 PM.. Reason: Code tags
# 6  
vi $(ls -t abc*.log | head -1)

Last edited by Scott; 05-19-2012 at 12:35 PM.. Reason: Code tags

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Computers
Difficulty: Medium
"Windows NT" is a monolithic kernel.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting latest entry in the log file

Hi there I am trying to write a script where I will need to look for a specific word in the log file and I am aware this can be done by grep for example. As there will be multiple entries for this I want to grep the last one to enter the log... how would I go about this - would I have to use... (5 Replies)
Discussion started by: simpsa27
5 Replies

2. Shell Programming and Scripting

Read latest file name with a date and time and then download from FTP

Hi All, Please help. I have requirement to read the file / folder based on the latest date and download the file and folder. There will be files and folders in the location like 20140630-144422 20140630-144422.csv 20140707-182653 20140707-182653.csv 20140710-183153... (7 Replies)
Discussion started by: Praveen Pandit
7 Replies

3. UNIX for Dummies Questions & Answers

How to pick the latest file with date as one among the file name.( not exactly present date.)?

i have files like 1)20131112_abc_01.csv and 2)20131113_abc_01.csv and 3)20131113_abc_02.csv when i try to fetch the file in the next day. it shud pick the third file.. plz help me.. and i use `date +"%Y%m%d"` command to fetches the current date... (2 Replies)
Discussion started by: applepie
2 Replies

4. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

5. UNIX for Advanced & Expert Users

Want to download a latest file with current date from FTP location

Dear Friends, I need help to write a shell / perl script to download the files from FTP location, having different file names (date inside the file name). Example: Mar 5 09:24 cfx_03052013_return_file.txt Mar 6 02:13 cfx_03062013_return_file.txt Mar 7 06:40... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

6. UNIX for Dummies Questions & Answers

Removing duplicate rows & selecting only latest date

Gurus, From a file I need to remove duplicate rows based on the first column data but also we need to consider a date column where we need to keep the latest date (13th column). Ex: Input File: Output File: I know how to take out the duplicates but I couldn't figure out... (5 Replies)
Discussion started by: shash
5 Replies

7. Shell Programming and Scripting

RSYNC syntax for pushing file with latest system date

OK, I am a little new to AIX 5.3 and also to scripting. I have a shell script that I wrote and am having difficulty pushing specific files by the system date. Here is my script: #!/usr/bin/sh RSYNC=/usr/local/bin/rsync SSH=/usr/local/bin/ssh KEY=<path> somekey.key RUSER=mike... (4 Replies)
Discussion started by: tfort73
4 Replies

8. Shell Programming and Scripting

grep latest file based on date.

hi all, not sure if this has been posted b4 but i try to search but not valid. this is my question: when i do a ls -ltr there will be a list generated as follows: -rw-r--r-- 1 root sys 923260 Jan 10 04:38 FilePolling.41025.083TL021.xml -rw-r--r-- 1 root sys 1761337 Jan 10 04:40... (12 Replies)
Discussion started by: lweegp
12 Replies

9. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies

10. Shell Programming and Scripting

Loop through files in dir, omit file with latest date

I want to loop through files in a directory but omit the file with the latest date in my list of files. How would I accomplish this? Thanks (2 Replies)
Discussion started by: stringzz
2 Replies

Featured Tech Videos