Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
"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
up vote 6 down vote accepted

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 ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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