LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-25-2009, 10:04 PM   #1
TiredOfThis
Member
 
Registered: Oct 2007
Posts: 53

Rep: Reputation: 15
Sort folder to top of list


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).

Thanks.
 
Old 01-26-2009, 01:27 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
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.)
 
Old 01-26-2009, 08:59 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.:
Code:
rm -- -filestartingwithadash

rm ./-filestartingwithadash
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".
 
Old 01-26-2009, 11:28 AM   #4
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by David the H. View Post
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.
 
Old 01-26-2009, 06:14 PM   #5
TiredOfThis
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
I find that neither ls nor Konqueror uses ASCII; rather, the file is sorted as though the special character were not there.

Code:
[nathan@ebisu ~/tmp/sort] ls -l
total 0
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 a
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 A
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 bar
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 baz
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 foo
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 test
-rw-r--r-- 1 nathan users 0 2009-01-26 19:14 _test
-rw-r--r-- 1 nathan users 0 2009-01-26 19:14 +test
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 z
-rw-r--r-- 1 nathan users 0 2009-01-26 19:13 Z
 
Old 01-26-2009, 07:43 PM   #6
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by TiredOfThis View Post
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.
 
Old 01-26-2009, 08:08 PM   #7
TiredOfThis
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
Losing the ability to display files with non-ASCII characters to appease my sorting neuroses isn't a tradeoff I'm willing to make

In case you're curious, here's a partial result from some more testing:
Code:
-rw-r--r--  1 nathan users    0 2009-01-26 19:13 test
-rw-r--r--  1 nathan users    0 2009-01-26 19:14 _test
-rw-r--r--  1 nathan users    0 2009-01-26 19:14 +test
-rw-r--r--  1 nathan users    0 2009-01-26 21:04 。test
-rw-r--r--  1 nathan users    0 2009-01-26 21:05 !test
-rw-r--r--  1 nathan users    0 2009-01-26 19:13 z
-rw-r--r--  1 nathan users    0 2009-01-26 19:13 Z
-rw-r--r--  1 nathan users    0 2009-01-26 21:03 一test
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.
 
  


Reply



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
Kopete - Sort contact list Wynd Linux - Software 2 06-19-2008 09:08 PM
find all files in current folder and all subfolders and sort all by timestamp dlnlinux Linux - Newbie 2 06-03-2008 11:29 AM
python list.sort() buggy? notnor Programming 3 05-18-2008 12:29 AM
How can I sort out the first and last of a list of uniques?!?!! vous Programming 8 03-22-2005 09:05 AM
C++, using custom function to sort an std::list R00ts Programming 3 01-03-2005 09:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:22 AM.

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