How to sort results from ls command by modification date (directories first)?

73,806

Solution 1

what about something like this:

ls -ltr --group-directories-first

Solution 2

ls -t

or (for reverse, most recent at bottom):

ls -tr

The ls man page describes this in more details, and lists other options.

Directories have d in front of there permissions in ls -ltr

So to get directories with sorted modification date use

ls -ltr |grep ^d

And to files other than directories

ls -ltr | grep -v ^d

Share:
73,806

Related videos on Youtube

jrara
Author by

jrara

Updated on September 18, 2022

Comments

  • jrara
    jrara almost 2 years

    I can fire

    ls -lrt 
    

    to get files and folders sorted by modification date, but this does not separate directories from files. I want ls to show me first directories by modification date and then files by modification date. How to do that?

  • jrara
    jrara almost 11 years
    No, this does not produce the correct result.
  • jrara
    jrara almost 11 years
    You are correct about folders, I updated question.
  • cblemuel
    cblemuel almost 11 years
  • jrara
    jrara almost 11 years
    Thanks for your answer, but if you read my question carefully, you might notice that I already know how to sort ls output by modification date (ls -lrt), but not how to sort results so that I get directories first by mod date and then files by mod date.
  • cblemuel
    cblemuel almost 11 years
    hey jrara i have got your question.. i am getting back with the answer...