Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Does anyone know a way to re-arrange the ls -al returned list in a way that:

a) Directories first, files after;

and

b) Date first, name second and permissions at the end

and

c) Without losing color. (CLICOLOR=1 do exist)

and

d) All this on a ls -al alias ?

share|improve this question
    
-1 Question shows no research effort (at least the awk part). –  Daniel Beck May 20 '12 at 19:11
    
Doesn't answer all parts of the question, but a simple solution to get group-directories-first is to install the GNU Coreutils. See: superuser.com/questions/545479/… –  Johann Jan 3 at 20:28

1 Answer 1

up vote 2 down vote accepted

How about

ls -la --color=yes --group-directories-first | awk '{print $6 "\t" $8 "\t\t" $1}'

About the alias, aliases cannot contain variables, but a solution would be functions. They are stored in .profile/.bashrc and work just like aliases.

EDIT: Function is below - just add it to your .profile, open a new shell and type myls. Works like a charm :)

myls () { ls -la --color=yes --group-directories-first | awk '{print $6 "\t" $8 "\t\t" $1}'; }
share|improve this answer
    
Doesn't work. ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...] –  MEM May 20 '12 at 12:45
    
If I simple do: ls -la --group-directories-first it doesn't work. Perhaps it's a mac osx limitation that doesn't other on some others nix distros. –  MEM May 20 '12 at 12:46
    
Heh I just took a look at the ls manual under OSX and indeed it misses the options with --. Couldn't find other options to replace these though... –  Silviu May 20 '12 at 13:15
    
Thanks Silviu. Actually this is a start but, if I use this, I loose the colors. :( superuser.com/questions/109537/… –  MEM May 20 '12 at 13:44
    
ah cool so how about ls -laG | grep "^d" | awk '{print $6 "\t" $8 "\t\t" $1}' && ls -laG | grep -v "^d" | awk '{print $6 "\t" $8 "\t\t" $1}' –  Silviu May 20 '12 at 17:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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