Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Kind of a silly question, but it's been bugging me -_-
In Windows, I would 'hack' the file order by naming folders I wanted at the top of an alphabetical file list with a _ at the beginning. Linux appears to be too clever for this trick, and all non-alphanumeric characters I tried don't seem to work out. Is there a way to make this happen under Konqueror (obviously naming the folder something like 0000 or aaaa is a suboptimal solution).
By default, the command line command ls will sort dashes (-) before numbers or letters. So I played around with Konqueror 3.5.5 ... The view menu allows you to select sort order. When set to by Name (Case Insenitive) I saw the behavior you describe. (It seems to be ignoring -- at least on the first pass of the sort -- all non-alphanumberic character.) However, when I set it to by Name (Case Senitive), it sorts (I believe) by the same order as the default for ls. In any case (no pun intended), I created folders with the names "-dir" and "-zdir" and these appeared before the others.
If you want to leave the sort to be case insensitive, you might be stuck with something like using a leading zero. (Numbers are sorted before letters.)
The sorting order depends on the system locale you have set. With the posix "C" locale, you get the dashes at the beginning, but if LC_COLLATE is set differently (many, if not most, systems use a UTF-8 encoding these days), you get a different sorting order. For me, using en_US.UTF-8, dashes show up at the end of the list.
Also, using a dash at the beginning of a file causes headaches when using the shell. With most commands you have to use either a double-dash or "./" before the filename, or else most programs will think it's a command option. e.g.:
Frankly, I'd like to know what the actual order is supposed to be also. Google seems to give you a lot of info about the sort order, but not much on the order itself. As it is, when I need something to appear at the beginning of the sort list, I usually preview it with a number, like "00_somefile, 01_someotherfile, 02_yetanotherfile".
The sorting order depends on the system locale you have set. With the posix "C" locale, you get the dashes at the beginning, but if LC_COLLATE is set differently (many, if not most, systems use a UTF-8 encoding these days), you get a different sorting order. For me, using en_US.UTF-8, dashes show up at the end of the list.
Thanks for the added info. After posting I did a bit more checking, and on my machine the ls command is sorting by ASCII value. If this holds for Konqueror (and it corresponds to the setting of the OP's machine) any of the characters prior to ASCII zero will work. So a comma or plus sign would work and would get around the problem you mentioned about the shell. (Some shell commands may have problems with the plus sign.) Also, if Konqueror is set to sort case sensitive, the OP could just start the name with a capital letter to move it toward the top and start other folders with a lower case letter.
Last edited by blackhole54; 01-26-2009 at 11:31 AM.
I find that neither ls nor Konqueror uses ASCII; rather, the file is sorted as though the special character were not there.
As pointed out by David the H., environmental variables change this behavior. He mentioned LC_COLLATE, but I have just demonstrated that LANG can impact it also. I have never really familiarized myself with the locale variables, but IIRC there are several locale variables that can impact things like this.
The machine I tried the ls command on when I first posted was running ancient software. I just tried it again on a Ubuntu 6.10 system, which is what I did my previous konqueror test on. On this machine LC_COLLATE is not defined but LANG is set to en_US.UTF-8. With that setting I got the same result you just posted. However
Code:
LANG= ls -l /tmp/sort
gave what appeared to be sorting by ASCII order like I previously posted. (LANG= sets the LANG variable to the empty string for the ls command.)
Where it gets interesting is when I tried to investigate konqueror further. This is the same machine I tried my earlier tests on, but I was running those under KDE. I am now in GNOME on that machine and (because I didn't see any other way) I started konqueror from a terminal window. It spat out a bunch of errors on the terminal but proceeded to open up konqueror. The weird thing is it displayed yet a different sorting order from either ASCII or what I observed when konqueror was running under KDE.
So I don't know what all might affect the sort order of konqueror. Environmental variables? Other settings? I tried to do some Internet searching but didn't really find anything. Maybe you will have better luck or might find something from playing around. Or you could just content yourself with using something like David the H.'s solution (numbers + underscore) or with capital vs lower case letters.
Even using foreign language punctuation symbols doesn't seem to faze the sort order, but using actual ideograms, of course, does. Naturally, that makes tab completion a pain because I have to switch input methods just to get the first character
Thanks for the help/fun experimentation. This problem isn't nearly vexing enough to warrant the effort/research it seems like it would require, but if I find time I'll play around with konqueror some more.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.