Avatar of royjayd
royjayd
 asked on

finding the latest file

hi guys

when i do
$ls -ltr  i get

-rwxrwxrwx 1 smwldvg steopsx  23429 Jul  3 13:36 EMPLOYEE_MASTER.rer
-rwxrwxrwx 1 smwldvg steopsx     0 Jul  3 08:18 EMPLOYEE_MASTER.rer

how can i write a command which will give me the latest file.
I want to see the file with the latest time 13:36.

any idea how i can do that?

thanks
Linux OS Dev

Avatar of undefined
Last Comment
royjayd

8/22/2022 - Mon
omarfarid

try

ls -ltr | head -2 | tail -1
ASKER CERTIFIED SOLUTION
farzanj

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
omarfarid

sorry, what I gave is not correct. It would work without -r option:

ls -lt | head -2 | tail -1
royjayd

ASKER
ls -lrtc | tail -l

gives me the latest one modified file

ls -lrtc | tail -16
gives me the latest  sixteen modified files

Am i correct ?

thanks
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
omarfarid

yes
royjayd

ASKER
alright, thanks
can you tell me what head does ?

ls -lt | head -2 | tail -1  -- what does it mean ?
SOLUTION
farzanj

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
omarfarid

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
royjayd

ASKER
thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.