Listing only the most recent file
Patrick Asselman
iceblink at seti.nl
Tue Oct 16 12:43:59 UTC 2012
On 2012-10-16 14:33, ping wrote:
> 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
Then it would have to be
ls -lt | head -2 | tail -1
otherwise you get the "total nnnn" line as well ;-)
Best regards,
Patrick Asselman
More information about the ubuntu-users
mailing list