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 10-01-2009, 12:45 AM   #1
shravee
Member
 
Registered: Sep 2009
Posts: 84

Rep: Reputation: 16
Post how to sort filenames numerically.


hi,

I am using Red hat linux .. i just wanted to know , is it possible to arrange or sort filenames numerically ?

i have saved several files with the follwing names : 1.png, 2.png, 3.png, 4.png ...... 11.png 12.png. and so on....

but the containing folder sorts this alphabetically in the following manner
11,12,13...... 1, 2, 3, and so on...


regards
shravee

Last edited by shravee; 10-01-2009 at 02:02 AM.
 
Old 10-01-2009, 12:54 AM   #2
Ralfredo
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Rep: Reputation: 0
Quote:
is it possible to arrange or sort filenames numerically ?

i have saved several files with the follwing names : 1.png, 2.png, 3.png, 4.png ...... 11.png 12.png. and so on....

but the containing folder sorts this alphabetically in the following manner
11,12,13...... 1, 2, 3, and so on...
Try:
Code:
ls | sort -n
And see if that does what you want.
 
Old 10-01-2009, 01:42 AM   #3
shravee
Member
 
Registered: Sep 2009
Posts: 84

Original Poster
Rep: Reputation: 16
Angry but how to retain the same in GUI

hi ralfredo,

i tried the command and it works fine in terminal or konsole.

in case of GUI whenever i open the folder, the order appears in the same view..


i followed the foll: view > sort > by type/ by size/ by case sensitive and so on........

but none could solve my issue or satisfy my requirement.

regards

shravee

Last edited by shravee; 10-01-2009 at 01:48 AM.
 
Old 10-01-2009, 01:55 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by shravee View Post
hi ralfredo,

i tried the command and it works fine in terminal or konsole.

in case of GUI whenever i open the folder, the order appears in the same view..


i followed the foll: view > sort > by type/ by size/ by case sensitive and so on........

but none could solve my issue or satisfy my requirement.

regards

shravee
You have two choices:

1. Rewrite the GUI file utility to meet your needs (the source is available to you).

2. Rename the files so they have enough digits to naturally sort numerically.

The second way sounds like a better idea. Files with one- and two-digit prefixes should be renamed to have four-digit prefixes:

1.png -> 0001.png
2.png -> 0002.png
3.png -> 0003.png

10.png -> 0010.png
11.png -> 0011.png

This way, no matter how you list the files or in what environment, they will always sort as you expect.
 
Old 10-01-2009, 01:57 AM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Quote:
Originally Posted by shravee View Post
hi ralfredo,

i tried the command and it works fine in terminal or konsole.

in case of GUI whenever i open the folder, the order appears in the same view..


i followed the foll: view > sort > by type/ by size/ by case sensitive and so on........

but none could solve my issue or satisfy my requirement.

regards

shravee
Hi shravee...

ls | sort -n will satisfy your requirment in command prompt...

But in GUI you will not be having as much options as you have in command prompt..its very limited....

you can observe here ls is combined with sort to get your work done in cmd prompt...Hope your requirement is not possible to meet through GUI..

If it is very much necessary for you then you have to develop your own browser using QT or GTK++ and add your option there....
 
Old 10-01-2009, 02:02 AM   #6
shravee
Member
 
Registered: Sep 2009
Posts: 84

Original Poster
Rep: Reputation: 16
hi lutusp,

As i am using red hat linux i dont have the source code available........

but tried ur second methos and it worked fine..........

but do let me know if there is a better solution, though i am following the above same.

-- shravee
 
Old 10-01-2009, 02:22 AM   #7
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by shravee View Post
As i am using red hat linux i dont have the source code available
Actually yes, you do have the source code available. All Red Hat software is open-source by definition. The fact that you pay for some Red Hat products doesn't mean they don't publish the source (or are relieved of responsibility to publish the source).

But the choice to rename all your files with multi-digit numerical prefixes is the best, most robust approach in any case.
 
  


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
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 12:23 AM
php sort help - sort numerical descending then by alphabetical? RavenLX Programming 3 03-11-2009 08:35 AM
How do I do filtering in Perl (keep sort order and sort again by another means)? RavenLX Programming 9 12-19-2008 10:12 AM
selection sort compiles but does not sort the array as desired ganesha Programming 2 04-20-2008 07:44 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM

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

All times are GMT -5. The time now is 09:23 PM.

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