Bash – How to list hidden directories, then directories, then hidden files and finally files with ls

bashlssort

I'm trying to figure out how to list the contents of a directory in the following group order:

  1. Hidden directories
  2. Non-hidden directories
  3. All other hidden files (including regular files, symlinks, sockets)
  4. All other non-hidden files (including regular files, symlinks, sockets)

Each group should be sorted A-Z, preferably case-insensitive.

Based on this answer I tried the following:

ls -dlU .*/ */

This gets me half-way there by listing hidden directories and then non-hidden directories. The problem is it doesn't list any files.

I've also tried various ways of piping the output to sort with no luck.

How can I do this?

Best Answer

The straightforward way :

find . -maxdepth 1 -type d -name '.*'
find . -maxdepth 1 -type d \! -name '.*'
find . -maxdepth 1 -type f -name '.*'
find . -maxdepth 1 -type f \! -name '.*'
Related Question