21

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?

2 Answers 2

25

what about something like this:

ls -ltr --group-directories-first
1
  • Great, thanks! Somehow I was not able to find this from the man page. My bad, thanks!
    – jrara
    Aug 11, 2013 at 9:49
5

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

5
  • No, this does not produce the correct result.
    – jrara
    Aug 11, 2013 at 9:39
  • You are correct about folders, I updated question.
    – jrara
    Aug 11, 2013 at 9:41
  • 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.
    – jrara
    Aug 11, 2013 at 9:44
  • hey jrara i have got your question.. i am getting back with the answer... Aug 11, 2013 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.