Changing the order of columns displayed with `ls`

3

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)?

warren

Posted 2011-07-15T10:29:50.950

Reputation: 8 599

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

Answers

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.

glenn jackman

Posted 2011-07-15T10:29:50.950

Reputation: 18 546

and what would be the equivalent for mac ? On mac I am getting stat: illegal option -- - usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...] – ishandutta2007 – 2019-10-17T11:07:09.027

What does the man page say? – glenn jackman – 2019-10-17T11:48:43.490