Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-24-2011, 12:36 PM   #1
LQ Newbie
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
Alpha Sort order for Linux Filenames and Directories

Hello, total newbie with a question that I can't figure out.

In Windows and DOS, for years I have used the characters such as underscore, tilde, caret etc. at the beginning of directory names to cause them to go to the top of a file listing. So, in a listing, _Alpha comes before Alpha which comes before Beta.

This same practice works in web apps like Gmail.

In Linux, both File Manager and apps like Thunderbird effectively ignore the pre-characters, so that _Beta comes after Alpha.

Without getting into scripts and macros, what is the sort order in Linux and/or what do the naming conventions allow me to do so that I can create a prioritized directory or file name? Or to restate the obvious, which non-alphanumeric characters sort before the alpha characters?

Thanks for any help.
Old 10-24-2011, 01:11 PM   #2
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Linux doesn't sort filenames. It depends on how the program that you use to list them decides to sort them.

I don't know whether GUI file managers follow this, but command line programs like "ls" use locale environment variables to decide how to sort stuff. For example:

$ export LC_COLLATE=en_US.UTF-8
$ ls
_  2  a  A  b  B
$ export LC_COLLATE=C
$ ls
2  A  B  _  a  b
The "LC_COLLATE" variable specifies the locale just for sorting. If it's not set, it also looks into the general "LC_ALL" and "LANG" variables. Also note that "C" and "POSIX" are the same, and they specify sorting by ASCII value.

Last edited by MTK358; 10-24-2011 at 01:19 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Nautilus to sort filenames in good ol' lexicographical order? Dan04 Linux - Software 1 03-14-2010 06:22 PM
[SOLVED] how to sort filenames numerically. shravee Linux - Newbie 6 10-01-2009 02:22 AM
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 12:23 AM
How do I do filtering in Perl (keep sort order and sort again by another means)? RavenLX Programming 9 12-19-2008 10:12 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:46 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration