LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-05-2014, 02:04 AM   #1
Tachtory
Member
 
Registered: Dec 2011
Distribution: Mint, Slackware
Posts: 43

Rep: Reputation: Disabled
Sorting files and directories before others


I know of preceding files and directories with '.' to make them 'hidden', but what about making some directories 'important' by making them sort to the top of the ls output.

A while back I made the mistake of prepending directories and files with '_', which Windows sorts before alphabetic characters, but Linux puts between numbers and alpha characters (probably because of the ordering if ISO character sets this is where the underscore is placed).

So I did some tests and found that many of non-alphanumeric characters are allowed for directory names, but many of them require escaping with '\'. I decided this is against what I am trying to do with making directories easier to find and get to.

Three valid characters I found that do not need escaping are %, + and ','. I am leaning toward using ',' because it is easier to type than either % or + (not requiring the shift key), and it seems more like a counterpart to the '.' prefix. Really the only drawback is ',' is rather low in the ordering of special characters, so pretty much any files or folders beginning with other special characters would be placed before these (I think '!' comes before all others).

Are there any side-effects I should be aware of before adopting this scheme? This is more for personal working/archival directories (not within system directories) so I should in theory have greater control of what names get used.
 
Old 01-05-2014, 05:11 AM   #2
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Sorting is influenced by the locale that is being used, especially the LC_COLLATE setting. Have a look at these examples:
Code:
$ LC_COLLATE=en_US.utf8
$ ls -la
drwxr-x--- 8 druuna druuna  4096 jan  5 11:04 .
drwxr-x--- 4 druuna druuna 16384 jan  5 10:34 ..
drwxr-x--- 2 druuna druuna  4096 jan  5 11:04 dir
drwxr-x--- 2 druuna druuna  4096 jan  5 11:04 _dir
drwxr-x--- 2 druuna druuna  4096 jan  5 11:04 .dir
drwxr-x--- 2 druuna druuna  4096 jan  5 11:03 Dir
drwxr-x--- 2 druuna druuna  4096 jan  5 11:03 _Dir
drwxr-x--- 2 druuna druuna  4096 jan  5 11:03 .Dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 file
-rw-r----- 1 druuna druuna     0 jan  5 11:04 _file
-rw-r----- 1 druuna druuna     0 jan  5 11:04 .file
-rw-r----- 1 druuna druuna     0 jan  5 11:04 File
-rw-r----- 1 druuna druuna     0 jan  5 11:04 _File
-rw-r----- 1 druuna druuna     0 jan  5 11:04 .File
and now with LC_COLLATE set to POSIX (or C):
Code:
$ LC_COLLATE=POSIX
$ ls -la
drwxr-x--- 8 druuna druuna  4096 jan  5 11:04 .
drwxr-x--- 4 druuna druuna 16384 jan  5 10:34 ..
drwxr-x--- 2 druuna druuna  4096 jan  5 11:03 .Dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 .File
drwxr-x--- 2 druuna druuna  4096 jan  5 11:04 .dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 .file
drwxr-x--- 2 druuna druuna  4096 jan  5 11:03 Dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 File
drwxr-x--- 2 druuna druuna  4096 jan  5 11:03 _Dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 _File
drwxr-x--- 2 druuna druuna  4096 jan  5 11:04 _dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 _file
drwxr-x--- 2 druuna druuna  4096 jan  5 11:04 dir
-rw-r----- 1 druuna druuna     0 jan  5 11:04 file
I have set LC_COLLATE to POSIX, which uses the order shown in the ascii table (man ascii). I have a rather simple schema I use for personal files and directories: Directories start with a capital and files do not, the sorting order I get by doing this is: hidden (dot) files than directories than files.

If at all possible I try to avoid using special characters (% + , etc) due to problems that might arise when scripting/programming.
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [PHP] I need help sorting directories on my forum. errigour Programming 2 03-31-2012 09:17 AM
[SOLVED] Need help sorting large number of files by timestamp and then greping those files scottjn Linux - Newbie 4 01-14-2011 11:42 AM
sorting through large file directories n_hendrick Linux - General 4 05-08-2007 01:08 PM
Sorting files in BASH deleted/ Linux - Newbie 16 01-26-2006 07:03 AM
Sorting Amarok Collection into directories nicholas.perkins Linux - Software 3 11-09-2005 07:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:20 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