Listing only the most recent file
Kelly Dunlop
kelly at xyzzy.org.uk
Tue Oct 16 10:36:46 UTC 2012
On Tue, Oct 16, 2012 at 11:26:19AM +0100, Oliver Marshall wrote:
> Hi chaps
>
> I need some help with an ls syntax.
>
> I want to show *only* the most recent file.
>
> "ls -St -1" gives me the contents of a dir with the most recent on top but
> I want only that most recent file shown.
>
> Can this be done?
Hi Olly,
I'd use:
ls -ltr | tail -1
"t" sorts by time
"r" reverses it so the newest file is at the bottom
the tail -1 gives you the last line.
Lose the l if you just want the filename.
Your ls -St seems to put together two conflicting sort options. S says sort
by file size and t sort by time.
Hope this helps
Kelly
--
Kelly Dunlop
kelly at xyzzy.org.uk
More information about the ubuntu-users
mailing list