LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-27-2012, 02:02 AM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
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
 
Old 01-27-2012, 02:17 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
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
 
  


Reply

Tags
bash, files, folder, nautilus, sorting



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
bash scripting: sorting and using using multiple files in a script daberkow Linux - Newbie 8 05-28-2009 09:24 AM
sorting a file at a certain offset in bash matt007 Linux - Software 4 06-24-2008 04:03 PM
sorting a file using bash on a certain field matt007 Linux - Newbie 1 06-24-2008 12:05 PM
bash: sorting a bunch of files into two halfs by size, and other tasks PatrickMay16 General 2 01-19-2008 01:04 AM
Sorting files in BASH deleted/ Linux - Newbie 16 01-26-2006 06:03 AM

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

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