ls
option --group-directories-first
causes directories to be listed on the top, which makes the output of ls
nice and clean:
ls -l --group-directories-first
However, it does not act on symlinks
, which are actually symlinks
to directories. There is a possibility to use
ls -l -L --group-directories-first
which will list both kind of directories on top, but will not distinguish between proper directory and symlinked directory, which is again confusing.
Can ls
display symlinked directories on top, while still keeping them distinct from regular directories?
EDIT:
I am using bash
.
ls
. According to thestat()
system call, a symbolic link to a directory is still a directory (S_ISDIR(st_mode)
will return true). Evidentiallyls
discounts the symlinks before it checks this.ls
doeslstat()
(andreadlink
for symlinks) unless you use the-L
option (in which case it usesstat()
)S_ISLNK(st_mode)
also returned true viastat()
, but it doesn't -- it only does so vialstat()
. Also that ISLNK doesn't return true via stat even if the link is a link to a link. Meaning thatISLNK
might never returns true via stat, although that's kind of unspecified...stat
gives you the properties of the file at the end of the symlink(s). If that doesn't exist or is not accessible, thestat
returns a ENOENT, so what is returned bystat
will never be a symlink.stat()
will never tell you anything about symlinks, just likeopen
will never open the symlink, orchmod()
will not change the permissions of a symlink... etc.