I would like to use ls command to first show direcotries and then files. I tried
ls -la | sort -k 1
But I got a wrong order.
|
feedback
|
|
The following command will list directories first, ordinary files second, and links third.
Also, it would make a great deal of sense to create an alias for this command to save keystrokes. Edit: If you want directories first, and then everything that is not a directory second, use this:
| ||||
feedback
|
|
I do so love *nix and love seeing the inventiveness that goes into some of these replies... Mine's not nearly as fancy on GNU Linux :
| |||||
feedback
|
|
Here's a function to do this (bash or zsh): And... I'm not suggesting this is the best way, but it's the one I came up with and am using right now:
function lss
{
# Shows directory listing with directories at the top.
command ls --color=always $@ | egrep '^d|total'
command ls --color=always $@ | egrep -v '^d|total';
}
| |||
|
feedback
|
|
You've got several choices, depending if you want to keep alphabetical order. You could simply try :
or this, to keep alphabetic order for files with the same permissions :
or, as eleven81 said (but this version lists everything) :
| |||
feedback
|
|
To delerious010's answer, I would add that if you want old-style ordering:
(or use LC_ALL or LANGUAGE or LC_COLLATE set to "C"). This will give something similar to:
Although, if I recall correctly, the hidden dot files originally appeared before the directories. | |||
|
feedback
|
|
| |||
feedback
|
|
Here is a good web site, Unix LS Command, 15 best practices It's detailed and a lot of information is listed. There is also the LS Wikipedia page that can give some good information. Hope this will help! David. | |||||||||||||
feedback
|
-comes beforedwhen usingsort– Nifle Feb 16 '10 at 13:32