I have a cron job that, among other things, does a recursive ls of a directory into a file. This gets compared to another file that I've created that, supposedly, contains an identical listing of the same directory. My problem is that, when I generate the version for comparison, I get the files listed in case-insensitive order. When the cron job runs, its list comes out in case-sensitive order.

How can I get both of these to come out the same way (I don't care which)? My call to ls is /bin/ls -lR --time-style=long-iso *; as far as I can tell, LC_COLLATE is not set in either setting.

  • 4
    "as far as I can tell"? Have you simply run both with LC_ALL=C ls ...? – Hauke Laging Jun 3 '13 at 20:26
  • No, but that seems to work nicely -- thanks! If you re-enter it as an answer, I'll be happy to give you the points. – Jim Miller Jun 3 '13 at 21:36
  • In my experience, anything odd that happens in a cron job is due to 1) cron's very limited environment, or 2) unescaped percent signs in the command. – glenn jackman Jun 4 '13 at 1:24

Sorting problems can be avoided by explicitly forcing applications to use a certain sort order. You can check the current locale by running locale instead of the program in question and compare the output of different call situations.

The sort order can be forced by setting LC_COLLATE / LC_ALL within the command line:

LC_ALL=C     ls ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.