5

Is it possible to change the order of displayed columns when running ls -l on *nix (or dir on Windows)?

For example, I'd like to see the date modified, then the name, then other fields (or select only the ones I want, and their order.

How would this be done without merely using cut and trimming undesired fields (since that does not address the issue of re-ordering)?

1
  • 1
    as a note regarding cut, you'd get more milage out of awk in this case. ls -al | awk '{print $3 " " $1}'
    – Sirex
    Commented Jul 15, 2011 at 11:27

1 Answer 1

3

I'd avoid parsing ls at all: use stat and sort:

stat --printf="%y\t%n\t%F\t%s\n" * | sort -t $'\t' -k 2

is a start.

4
  • 2
    and what would be the equivalent for mac ? On mac I am getting stat: illegal option -- - usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...] Commented Oct 17, 2019 at 11:07
  • 1
    What does the man page say? Commented Oct 17, 2019 at 11:48
  • this docs.google.com/document/d/… Commented Oct 18, 2019 at 3:57
  • It would be nice to provide answers, in addition to the one you provided here, that would work on other platforms like Mac OSx. We come here to find answers to our questions; it's a bit obnoxious that we get an answer that doesn't work when, if you understand what you're putting together, shouldn't be that much more work for you. Referring us to the man page isn't always helpful. That's why we come here because man pages are about as clear as mud.
    – A.Ellett
    Commented Jun 2 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .