Hi!
I try to list all files of a directory (including hidden files) but subdirectories first.
ls -lA | grep "^d" && ls -lA | grep "^-"
... works fine, but it doesn't list correctly where a directory contains links and no subdirectories.
Yes, you're instructing grep to only pick files (^-).
Try grep "^[^d]" instead.
You can also use "find -maxdepth 1 -mindepth 1 {-type d | -not -type d}" in lieu of ls+grep.
Or do something like
ls -p| sed "s_^.*/_!&_"| sort | sed "s_^!__"
to avoid parsing the filesystem twice.
Last solution is just a stub, and should be made more robust (e.g., using awk) for filenames starting with spaces, etc...