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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_up date.dat
But it's failing ... any clues ...
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_up
But it's failing ... any clues ...
ASKER
ch_kaushik