LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Questions about sorting files between BASH and file navigators (http://www.linuxquestions.org/questions/linux-newbie-8/questions-about-sorting-files-between-bash-and-file-navigators-925926/)

SilversleevesX 01-27-2012 03:02 AM

Questions about sorting files between BASH and file navigators
 
Hi.

I have a folder of files with many similar names. This is how BASH 4.2.8 in GNOME Terminal (Ubuntu 11.04) sorts them:
Code:

Clipboard-1newer.jpg
gae100-10052-013-001.jpg
gae100-10052-057-003.jpg
gae73-7342-249-842.jpg
gae75-7586-007-105.jpg
gae75-7586-951-001.jpg
gae78-7888-666-001.jpg
gae79-7955-032-001.jpg
gae88-8850-253-003.jpg
gae88-8850-254-001.jpg
gae88-8877-167-004.jpg
gae95-9598-078-001.jpg
gae95-9598-103-002.jpg
gae95-9598-115-007.jpg
gae95-9598-124-005.jpg
gae95-9598-186-003.jpg
gae95-9598-190-005.jpg
gae96-9616-022-003.jpg

While Nautilus 2.3.2.2, Dolphin 1.6.1, Konqueror 4.6.5 and my Windows 7 Explorer (in any view mode you care to mention) sort the same folder of files like this:
Code:

Clipboard-1newer.jpg
gae73-7342-249-842.jpg
gae75-7586-007-105.jpg
gae75-7586-951-001.jpg
gae78-7888-666-001.jpg
gae79-7955-032-001.jpg
gae88-8850-253-003.jpg
gae88-8850-254-001.jpg
gae88-8877-167-004.jpg
gae95-9598-078-001.jpg
gae95-9598-103-002.jpg
gae95-9598-115-007.jpg
gae95-9598-124-005.jpg
gae95-9598-186-003.jpg
gae95-9598-190-005.jpg
gae96-9616-022-003.jpg
gae100-10052-013-001.jpg
gae100-10052-057-003.jpg

You might notice that the files whose names start with "gae100-" are being sorted based on the value of "100" as a number, rather than, as appears to be the case in GNOME Terminal, the number "100" as a "10" with a "0" to the right of it.

My questions are:

1. Is there a name for how the three file navigators do it, like "natural order" ?
2. Is it possible to get BASH to list and sort the same way ?

I look forward to all the great and good replies.

BZT

fukawi1 01-27-2012 03:17 AM

I assume you mean when you use "ls" in bash.

Code:

~/tmp $ ls | sort -nr
gae96-9616-022-003.jpg
gae95-9598-190-005.jpg
gae95-9598-186-003.jpg
gae95-9598-124-005.jpg
gae95-9598-115-007.jpg
gae95-9598-103-002.jpg
gae95-9598-078-001.jpg
gae88-8877-167-004.jpg
gae88-8850-254-001.jpg
gae88-8850-253-003.jpg
gae79-7955-032-001.jpg
gae78-7888-666-001.jpg
gae75-7586-951-001.jpg
gae75-7586-007-105.jpg
gae73-7342-249-842.jpg
gae100-10052-057-003.jpg
gae100-10052-013-001.jpg

You can pipe the output of ls to sort, as shown above.
"man sort" for more information


All times are GMT -5. The time now is 06:02 PM.