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

MEM
  • 1,297
  • 5
  • 17
  • 29
  • -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: http://superuser.com/questions/545479/how-can-i-list-directories-first-in-the-terminal-with-zsh-ls-command-in-mac-os – Johann Jan 03 '14 at 20:28

1 Answers1

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}'; }
Silviu
  • 674
  • 6
  • 16
  • 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. :( http://superuser.com/questions/109537/unix-ls-how-to-sort-first-directories-then-files-etc – 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
  • Silviu, I'm really sorry for bother you again. :( Can you please check my question update. I see no creation date and, the list gets outlined somehow. Please advice. – MEM May 20 '12 at 19:08
  • @MEM `ls` has never listed creation date. – Daniel Beck May 20 '12 at 19:10
  • @Daniel Beck here is a line of an ls -la : -rw-r--r-- 1 mem staff 0B Oct 15 2011 .localized - Oct 15 2011 being a date. Perhaps a creation or modified date. Cheers. – MEM May 21 '12 at 08:02
  • Silviu: I want to thank you for your work. I will not use unfortunately your suggestion but it sure answers the question. Again, thanks a lot. – MEM May 21 '12 at 08:02
  • No prob. Have fun! :) – Silviu May 21 '12 at 15:21
  • @MEM It's either modification or change date, and not creation. That is what I was commenting on. – Daniel Beck May 21 '12 at 15:35