Latest list of files of each type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Latest list of files of each type
# 1  
Old 07-07-2018
Latest list of files of each type

Code:
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)

Code:
/tmp/testlog/log/KSR04_2018-07-06.log
 /tmp/testlog/log/KSR01_2018-07-06.log


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 07-07-2018 at 02:39 PM.. Reason: Added CODE tags.
# 2  
Old 07-07-2018
Code:
tail -2

# 3  
Old 07-08-2018
what happens if more than 2 files with latest dates and i need dynamic script

Code:
/tmp/testlog/log/KSR01_2018-07-05.log
/tmp/testlog/log/KSR01_2018-07-06.log
/tmp/testlog/log/KSR04_2018-07-06.log
/tmp/testlog/log/KSR03_2018-07-06.log

Moderator's Comments:
Mod Comment Getting 11 warnings to correctly use CODE tags when displaying sample input, sample output, and code segments and having several other cases where moderators have edited your posts to add CODE tags for you without issuing a warning has resulted in this account being placed in read-only mode for three days.

Please review the rules you agreed to when you joined this forum.

Future posting without proper formatting or breaking other forum rules may result in you being permanently banned from this site.
# 4  
Old 07-08-2018
I'm very confused...

The command:
Code:
find /tmp/testlog/kSR*"_"2018* -type f -printf '%T@ %p\n' | sort -n | tail -3 | cut -f2- -d" "

is never going to produce the output:
Code:
/tmp/testlog/log/KSR04_2018-07-05.log
/tmp/testlog/log/KSR04_2018-07-06.log
/tmp/testlog/log/KSR01_2018-07-06.log

because testlog/kSR* is never going to match testlog/log/KSR.

Are you trying to print all filenames with the latest date in the filename:
Code:
/tmp/testlog/log/KSR01_2018-07-06.log
/tmp/testlog/log/KSR04_2018-07-06.log
/tmp/testlog/log/KSR03_2018-07-06.log

???

Are you trying to print the most recently modified filenames with different numbers between KSR and _ (which in this case would be the same files)???

Are all of the files you're interested in in a single directory (as shown in your examples)? Or, are they spread out in various directories under the directory /tmp/testlog/log?

Is the first part of the filenames you want to match kSR or KSR?

What operating system are you using?

What shell are you using?

P.S. Is it OK if the most recent file is printed first instead of last?

If you're trying to get the most recent names with different numbers before the underscore, does the order of the output lines matter as long as the filenames you want are all printed?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

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

3. Red Hat

List all old files except 15 latest files

Guys, Someone please guide me to tell me how do I print and later remove all old files in a folder recursively but keep only latest 15 modified files. When I do - ls -tp | head -15 I get the list of last 15 modified files whereas I need the list of all OTHER files except these files. ... (3 Replies)
Discussion started by: rockf1bull
3 Replies

4. UNIX for Advanced & Expert Users

Getting Latest files

Hai I wolud like to know how to get the latest files. ex: file_ssss_00 file_ssss_01 i need to get file_ssss_01 files only. (in Unix script) Please give some idea ... (2 Replies)
Discussion started by: raju4u
2 Replies

5. UNIX for Dummies Questions & Answers

Help with list of latest file names

Hi Gurus, I need to list only those files which are most recent and the latest log file. For example if I have the following file list: JOB001.LOG_00uv02_00006 - Jul 7 12:16 JOB001.LOG_00vi0t_00001 - Aug 4 21:58 JOB001.LOG_00vi0t_00002 - Aug 5 09:15 JOB001.LOG_00vi0t_00003 - Aug 5... (6 Replies)
Discussion started by: shash
6 Replies

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

7. Shell Programming and Scripting

Retain 3 latest files

Guys, Please can you tell me how to retain 3 latest files in a directory and get rid of the rest ? Thanks very much Regards, Ganesh (6 Replies)
Discussion started by: kamathg
6 Replies

8. UNIX for Dummies Questions & Answers

Basic Q: getting list of all files of type within folder & subfolders

A painfully rudimentary UNIX question for somebody. I've been puzzling over this for the last hour but can't find the right command. I'm simply trying to get a list of all files - and their full paths - within a folder & subfolders which have extension .php and .js. That's it! No amount of... (1 Reply)
Discussion started by: AtomicPenguin
1 Replies

9. Shell Programming and Scripting

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. (1 Reply)
Discussion started by: Jayathirtha
1 Replies
Login or Register to Ask a Question