Advanced LS Output using Find for Formatted/Sortable File Stat info

find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n'
I love this function because it tells me everything I want to know about files, more than stat, more than ls. It's very useful and infinitely expandable. find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n' | sort -rgbS 50% 00761 drwxrw---x askapache:askapache 777:666 [06/10/10 | 06/10/10 | 06/10/10] [d] /web/cg/tmp The key is: # -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n' which believe it or not took me hundreds of tweaking before I was happy with the output. You can easily use this within a function to do whatever you want.. This simple function works recursively if you call it with -r as an argument, and sorts by file permissions. lsl(){ O="-maxdepth 1";sed -n '/-r/!Q1'<<<$@ &&O=;find $PWD $O -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n'|sort -rgbS 50%; } Personally I'm using this function because: lll () { local a KS="1 -r -g"; sed -n '/-sort=/!Q1' <<< $@ && KS=`sed 's/.*-sort=\(.*\)/\1/g'<<<$@`; find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n'|sort -k$KS -bS 50%; } # i can sort by user lll -sort=3 # or sort by group reversed lll -sort=4 -r # and sort by modification time lll -sort=6 If anyone wants to help me make this function handle multiple dirs/files like ls, go for it and I would appreciate it.. Something very minimal would be awesome.. maybe like: for a; do lll $a; done Note this uses the latest version of GNU find built from source, easy to build from gnu ftp tarball. Taken from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Sample Output
$ find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G  [%AD | %TD | %CD]  [%Y] %p\n' | sort -rgbS 50%
00761 drwxrw---x  askapache:askapache    777:666    [06/10/10 | 06/10/10 | 06/10/10]  [d] /web/cg/tmp
00755 drwxr-xr-x  askapache:askapache    777:666    [02/10/10 | 05/21/10 | 05/25/10]  [d] /web/cg/java
00701 drwx-----x  askapache:askapache    777:666    [06/10/10 | 06/10/10 | 06/10/10]  [d] /web/cg/askapache-m
00644 -rw-r--r--  askapache:askapache    777:666    [02/10/10 | 01/12/10 | 06/01/10]  [f] /web/cg/.htaccess


$ find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G  [%AD | %TD | %CD]  [%Y] %p\n'
00644 -rw-r--r--  askapache:askapache    777:666    [03/22/10 | 03/22/10 | 05/25/10]  [f] /h/wireshark/cmdarg_err.h
00755 drwxr-xr-x  askapache:askapache    777:666    [03/22/10 | 03/22/10 | 05/25/10]  [d] /h/wireshark/codecs
00644 -rw-r--r--  askapache:askapache    777:666    [03/22/10 | 03/22/10 | 05/25/10]  [f] /h/wireshark/color.h
00644 -rw-r--r--  askapache:askapache    777:666    [03/22/10 | 03/22/10 | 05/25/10]  [f] /h/wireshark/colorfilters

What Others Think

Thx, this looks fantastic.
oernii2 · 435 weeks and 6 days ago
Yeah I love it.. Here's the main function I use instead of ls, which I save as /usr/local/bin/ll or ~/bin/ll #!/bin/sh -r _W=$((${COLUMNS:-80} - 20 ));[[ $# -eq 0 ]] && command ls -vlaph -w $_W --color=always||for a;do command ls -vlaph -w $_W --color=always "$a";done; exit $?
AskApache · 435 weeks and 6 days ago
had to install the GNU findutils to get this to work as the OSX version of `find` doesn't have the -printf option. Very nice.
fukr · 364 weeks and 5 days ago
And gnu sed.
fukr · 364 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: