ksh: How to get latest file from a list of files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh: How to get latest file from a list of files in a directory
# 1  
Old 06-24-2003
ksh: How to get latest file from a list of files in a directory

Hi,

I need to get the latest file from a list of files in a particular directory.

Please could anyone help me out to get the file.

Thank you,
- Jay.
# 2  
Old 06-24-2003
See the man page for the ls command - note the -t and -r options.

-t Sorts by time stamp (latest first) instead of by name.
The default is the last modification time. (See -u and -c.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with UNIX command to get the latest file from list of files with timestamp

Hi All, I have list of files like below with name abcxyz.timestamp. I need a unix command to pick the latest file from the list of below files. Here in this case the lates file is abcxyz.20190304103200. I have used this unix command "ls abcxyz*|tail -1" but i heard that it is not the appropriate... (2 Replies)
Discussion started by: rakeshp
2 Replies

2. Shell Programming and Scripting

Latest list of files of each type

find /tmp/testlog/kSR*"_"2018* -type f -printf '%T@ %p\n' | sort -n | tail -3 | cut -f2- -d" " /tmp/testlog/log/KSR04_2018-07-05.log /tmp/testlog/log/KSR04_2018-07-06.log /tmp/testlog/log/KSR01_2018-07-06.log But, I would see the following output(latest files for each KSR tuype) ... (3 Replies)
Discussion started by: jhonnyrip
3 Replies

3. Shell Programming and Scripting

I have this list of files . Now I will have to pick the latest file based on some condition

3679 Jul 21 23:59 belk_rpo_error_**po9324892**_07212014.log 0 Jul 22 23:59 belk_rpo_error_**po9324892**_07222014.log 3679 Jul 23 23:59 belk_rpo_error_**po9324892**_07232014.log 22 Jul 22 06:30 belk_rpo_error_**po9324267**_07012014.log 0 Jul 20 05:50... (5 Replies)
Discussion started by: LoneRanger
5 Replies

4. Shell Programming and Scripting

How to retrieve the latest files from the directory.?

hi, i have some file in a directory say p1.txt.201305051200.lst p1.txt.201305051300.lst p1.txt.201306051200.lst p1.txt.201306051300.lst p2.txt.201306051200.lst p2.txt.201306051300.lst i am using p* pattern to retrieve these file ls -1 p* the files in red color are the latest... (7 Replies)
Discussion started by: Little
7 Replies

5. UNIX for Dummies Questions & Answers

Select the latest dated file-ksh script

Hello all!! I am new here and new in scripting! I want to write a ksh script to select the most recent file from a dir and use it in a variable. I have a directory with files named like: YYYMMDD A basic idea of the script I want to write is #!/usr/bin/ksh latest= latest_dated_file at... (2 Replies)
Discussion started by: chris_euop
2 Replies

6. Shell Programming and Scripting

KSH: Opening Files based on a file list

I'd like to grep files for key words using korn shell, and compile the actual contents (not just file name) of those files that contain a combination of those grepped key words into one repository file for reference. However, I'm stuck at the combining part. Here's what I have thus far: egrep... (5 Replies)
Discussion started by: drumminfool91
5 Replies

7. Shell Programming and Scripting

find the latest files in multiple directory

I want to get the latest files from multiple directories, d1, d2,d3 and d4 under the parent dierectoy d. can anyone help out with this? thx (3 Replies)
Discussion started by: shyork2001
3 Replies

8. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

9. Shell Programming and Scripting

Copying a directory structure with the latest versions of files

Hello I have three directory structures for code releases. Each directory structure looks like this: bash-3.00$ ls -R | more .: Test_Release_1 Test_Release_2 Test_Release_3 ./Test_Release_1/dbcode: rp_online_import_srdp.pkb-1 srdp_ar_validation.pkb-1... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

10. UNIX for Dummies Questions & Answers

To list only the very latest files

Hi, There are huge no of files in the directory. If i say ls -ltr it is taking too much time. i want to see only the files for Feb,2009. Please help. Thanks (3 Replies)
Discussion started by: venkatesht
3 Replies
Login or Register to Ask a Question