Listing only the most recent file
ping
songpingemail at gmail.com
Tue Oct 16 12:33:41 UTC 2012
On 10/16/2012 6:36 AM, Kelly Dunlop wrote:
> 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
how about "head" ?
ls -lt | head -2
More information about the ubuntu-users
mailing list