LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sorting files in a directory (https://www.linuxquestions.org/questions/linux-newbie-8/sorting-files-in-a-directory-780254/)

Shyju N 01-06-2010 07:32 AM

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

stefansbv 01-06-2010 07:49 AM

Try -v (--sort=version) option

% ls -1 -v *.txt

Simon Bridge 01-06-2010 07:51 AM

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

Shyju N 01-06-2010 07:54 AM

it worked..

thanks
Shyju N

linuxplayer 01-06-2010 08:06 AM

that's sounds interesting

Simon Bridge 01-06-2010 10:37 AM

Quote:

Originally Posted by Shyju N (Post 3816162)
it worked..

thanks
Shyju N

Cool!

... um

... what worked?


All times are GMT -5. The time now is 04:05 AM.