LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-06-2010, 08:32 AM   #1
Shyju N
LQ Newbie
 
Registered: Jan 2010
Posts: 3

Rep: Reputation: 0
sorting files in a directory


Hi,

I have some files in a directory like

file1.txt
file10.txt
file2.txt
file11.txt

I want to sort it to

file1.txt
file2.txt
file10.txt
file11.txt

How to do that..?

I tried like

ls -1 *.txt | sort

But it gave like

file10.txt
file11.txt
file1.txt
file2.txt

Can anyone help me..

Thanks
Shyju N
 
Old 01-06-2010, 08:49 AM   #2
stefansbv
LQ Newbie
 
Registered: May 2009
Distribution: Slackware
Posts: 17
Blog Entries: 1

Rep: Reputation: 9
Try -v (--sort=version) option

% ls -1 -v *.txt
 
Old 01-06-2010, 08:51 AM   #3
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
The files are sorted to character order - but you want them in numerical order.
When you number files, put in the leading zeros.
http://unstableme.blogspot.com/2009/...sing-bash.html
 
Old 01-06-2010, 08:54 AM   #4
Shyju N
LQ Newbie
 
Registered: Jan 2010
Posts: 3

Original Poster
Rep: Reputation: 0
it worked..

thanks
Shyju N
 
Old 01-06-2010, 09:06 AM   #5
linuxplayer
LQ Newbie
 
Registered: Jan 2010
Posts: 2

Rep: Reputation: 0
that's sounds interesting
 
Old 01-06-2010, 11:37 AM   #6
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by Shyju N View Post
it worked..

thanks
Shyju N
Cool!

... um

... what worked?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using konqueror .directory file for sorting files? Frank64 Linux - Software 2 04-24-2008 08:19 PM
Sorting files by time / date. TheRealDeal Linux - General 2 08-06-2006 10:35 PM
Sorting files in BASH deleted/ Linux - Newbie 16 01-26-2006 07:03 AM
HELP, sorting files by name with environment ar3ol Linux - Newbie 6 12-05-2005 05:03 PM
Sorting by directory size jbg_sm Linux - Newbie 3 04-21-2005 11:32 PM


All times are GMT -5. The time now is 08:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration