1

How can ls be flagged to sort .-prefixed hidden directories and files in groups so that its output is sorted as visible directories, hidden directories, visible files, then hidden files?

I currently have ls aliased to ls -lG --color --group-directories-first which groups directories first, but visible and hidden directories are mixed together.

Instead, the output of ls should be:

visibleDirectoryA
visibleDirectoryB
.hiddenDirectoryA
.hiddenDirectoryB
visibleFileA
visibleFileB
.hiddenFileA
.hiddenFileB
2
  • i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort). Commented Jan 13, 2018 at 6:19
  • My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= Commented Jan 13, 2018 at 6:56

1 Answer 1

7

Use -v for natural sort. e.g.

ls -lG --color --group-directories-first -A -v

Note while they are sorted into their own "group", the .hidden directories will appear before the visible directories, not after them, because a . sorts lower than most other characters.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.