chillibear.com

Sorting ls output by type

I was recently wondering if there was an easy way to list a directory on NIX and have all the directories listed first together. A popular search engine to the rescue and the following site was located http://superuser.com/questions/19781/make-ls-sort-by-file-type-then-name.

Now since I run the vastly wonderful FreeBSD and we errr, don’t have all those fancy Linux switches the last option was the one that interested me. Works a treat. Repeated here for reference:

ls -l |sort -d -k 1.1,1.1r -k 9 |awk '{print $9}'

Written on 29 May 2010 and categorised in FreeBSD and NIX, tagged as sort, ls, and directories

Home, Post archive

site copyright Eric Freeman

Valid XHTML 1.0 Strict