-1

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 ?

2
  • -1 Question shows no research effort (at least the awk part).
    – Daniel Beck
    May 20, 2012 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, 2014 at 20:28

1 Answer 1

2

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}'; }
11
  • Doesn't work. ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
    – MEM
    May 20, 2012 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, 2012 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, 2012 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, 2012 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, 2012 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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