Link to home
Start Free TrialLog in
Avatar of ch_kaushik
ch_kaushik

asked on

Reading a field from the last line, after ls -lrt

Hi,

can any one help me out with this one,

After typing in "ls -lrt", from the displayed contents, (i.e.)

Unix$>ls -lrt
-rw-r--r--   1 user1  group        2 Apr 12 15:06 123.dat
-rw-r--r--   1 user1  group        2 Apr 12 15:07 234.dat
-rw-r--r--   1 user1  group        2 Apr 12 15:08 345.dat
-rw-r--r--   1 user1  group        2 Apr 12 15:09 456.dat

I would like to read the latest updated file name, as here that would be "456.dat", using a shell script.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ch_kaushik
ch_kaushik

ASKER

Thanks Sunnycoder!

ch_kaushik
Sunnycoder one more point if you could reply,

How to insert the current date format in between a filename?

What I am trying is,

Date=`date '+%Y%m%d'`
File=`ls -lrt | tail -1 | awk '{print $9}'`
mv $File $HOME/abc/NewFile_$Date_update.dat


But it's failing ... any clues ...