0

This page: How can I make "ls" show dotfiles first? lets me list hidden files first, but I also wish to sort non-hidden files by "extension" e.g. all filenames ending with ".png" come after those ending with ".jpg".

ls -X does that, but the hidden files are no longer listed first (I suppose because their names begin with ".", their whole name is treated as their extension).

Is there a way to list hidden files first, and then non-hidden files sorted by extension? I'd prefer it to be wholly contained in the ls command, so that I can add further flags when needed.

Thanks!

1 Answer 1

1

You can use two commands: the first outputs the dotted files, the second lists the rest in the correct order:

ls -1 -d .* ; ls -X -1

You might need to use 'ls' with quotes to prevent aliases from changing the behaviour.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .