How do I sort the output of "ls" by last modified - including the date?

26,079

Check the -l option of ls:

ls -lt

Neat way using stat:

stat -c '%y - %n' * | sort -t'-' -k1,1

Reverse:

stat -c '%y - %n' * | sort -r -t'-' -k1,1
  • %y will give the modification time in human readable form, %n will give file name

  • sort will sort the values according to only the modiication time

Share:
26,079

Related videos on Youtube

TellMeWhy
Author by

TellMeWhy

I Wonder

Updated on September 18, 2022

Comments

  • TellMeWhy
    TellMeWhy almost 2 years

    So the output would be either:

    Most recent at the top OR most recent at the bottom - giving the times when the contents of the working directory were modified?

    Apparently, ls -t is supposed to give most recent at the top, which it does...

    But I have no date when any of the file/folders were modified; which is rather annoying.


    Is it possible to produce an output which lists the files in modified order, and also gives the time at which they were modified? I can't seem to find the option in man...