How do i make alphabetical file sorting order numbers correctly?

Screenshot of how dolphin sorts alphabetically, as you ucan see, it is wrongly sorted with 10 coming right after 1 and 2 coming after 11.
image

Screenshot of how ls sorts alphabetically, it is even worse, it sorts 10 & 11 before 1.
image

How do I fix this?

Use 01 instead 1 etc

Sorting in the terminal is char based. Numbers doesn’t work well

There was a similar topic some time ago - but this was using a file manager.

You need to understand that a machine sees chars differently and require a lot of rules to accomplish what seems obvious to a human.

2 Likes

For ls try:

ls --sort --version

If that will work you can make alias in .bashrc

For Dolphin go to this settings

3 Likes

Whether I want to use 01 or not doesn’t mean that everyone else in the world is gonna use 01 just to suit my needs, i’m not gonna format every single file on my computer just for this.

I do understand how machines see chars and I don’t really get why you’re insinuating that I don’t, point is this is possible, other operating systems have this kind of sorting feature, why is it so hard to get files sorted right on linux?

the ls thing you suggested didn’t work, but the dolphin setting does work, i’d tried it before and it didn’t seem to do anything but after you posted it i found out that you need to fully restart dolphin for it to start working.

After having had a look at the manual page for ls
I think the command
ls --sort --version
should have been
ls --sort=version
or just
ls -v

Also, of course what you want can be done as is evidenced by the graphical filemanagers ability to do it.

If ls alone cannot do it then you just have to take a different approach,
possibly chaining commands together.

and spaces in filenames generally do not make things easier …

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.