Red Hat Bugzilla – Bug 151959
ls | sort gives wrong order
Last modified: 2007-11-30 17:07:17 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2) Gecko/20040308
Description of problem:
when I use ls and sort commnd, It does not give the correct order. e.g. I have directory called temp, under temp, I created the following files:
Avoid BolusPTV CTV_CT GTV_CT markers PTV_CT skin. I use the touch command. then I issue the command ls | sort, it give me the results as "Avoid BolusPTV CTV_CT GTV_CT markers PTV_CT skin". The "markers" shall be after the "PTV_CT". This is a error or a bug
Version-Release number of selected component (if applicable):
Steps to Reproduce:
2. touch Avoid BolusPTV CTV_CT GTV_CT markers PTV_CT skin
3. ls | sort
Actual Results: Avoid BolusPTV CTV_CT GTV_CT markers PTV_CT skin
Expected Results: Avoid BolusPTV CTV_CT GTV_CT PTV_CT markers skin
You don't say what locale you are using, but presumably it is not the C locale
(which *would* give the order you cite).
To get the order you want, use:
ls | LC_COLLATE=C sort
ISO 14651, which is the sorting standard, specifies this behaviour. You can
also find some information in the strcoll documentation.
IEEE Std 1003.1, 2003 Edition, says that the sorting "shall be performed
using the collating sequence of the current locale".