5

I am creating image sprites and have neatly named around 100 files. I am using the following to generate an image sprite from individual images:

convert $(ls -w 1000) +append sprite.png

I have just noticed that Nautilus 3.4.2 sorts by name differently from ls.

Is there a way to get ls to use the same ordering as Nautilus (and not the other way around)?

Example

Nautilus order:

  • cloudy_with_heavy_rain.png
  • cloudy_with_heavy_rain_night.png

ls order:

  • cloudy_with_heavy_rain_night.png
  • cloudy_with_heavy_rain.png
Braiam
  • 69,302
Gibbs
  • 941

1 Answers1

9

Well this drove me mad for five minutes. Change your statement to:

convert $(LC_COLLATE="C" ls -w 1000) +append sprite.png

For some reason Nautilus doesn't follow the system-wide locale settings so sorts are out of sync. By faking back to the standard, sorts unify.


My test harness:

$ mkdir test && cd test
$ touch cloudy_with_heavy_rain{,_night}.png

$ ls -l
total 0
-rw-rw-r-- 1 oli oli 0 Apr 13 00:32 cloudy_with_heavy_rain_night.png
-rw-rw-r-- 1 oli oli 0 Apr 13 00:32 cloudy_with_heavy_rain.png

$ LC_COLLATE="C" ls -l
total 0
-rw-rw-r-- 1 oli oli 0 Apr 13 00:32 cloudy_with_heavy_rain.png
-rw-rw-r-- 1 oli oli 0 Apr 13 00:32 cloudy_with_heavy_rain_night.png
Oli
  • 299,936