make ls retrive ordered list of elements


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers make ls retrive ordered list of elements
# 1  
Old 07-05-2011
make ls retrive ordered list of elements

Hello friends!!

I have a question regarding the use of ls in unix. I have a folder with files:
Code:
t1.txt
t2.txt
t3.txt
t4.txt
...
t10.txt


When I make an ls I always get:

Code:
t10.txt
t1.txt
t2.txt
t3.txt
..
t9.txt

But I want to have the ordered list!!! i.e. t1.txt, t2.txt, .... t10.txt

How can I do it???? SmilieSmilieSmilie

Last edited by radoulov; 07-05-2011 at 12:22 PM.. Reason: Code tags please!
# 2  
Old 07-05-2011
The list you see is ordered, but it's ordered in ASCIIbetical order.
If you want to display the filenames in different order, you should use other tools:
Code:
% ls -1           
t1.txt
t10.txt
t2.txt
t3.txt
t4.txt
% ls | sort -k1.2n
t1.txt
t2.txt
t3.txt
t4.txt
t10.txt

This User Gave Thanks to radoulov For This Post:
# 3  
Old 07-05-2011
Thanks man! I didn't know about the -k1.2n, it worked perfectly!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find common values in python list in ordered format

Hello All, There are various codes available to find the intersection between two sets in python. But my case is the following: I want to find the continual common pattern in different lists compared to list1. (i have underlined the longest common patterns in set a and set b) a = 2, 3, 5,... (1 Reply)
Discussion started by: Zam_1234
1 Replies

2. Shell Programming and Scripting

Number of elements, average value, min & max from a list of numbers using awk

Hi all, I have a list of numbers. I need an awk command to find out the numbers of elements (number of numbers, sort to speak), the average value the min and max value. Reading the list only once, with awk. Any ideas? Thanks! (5 Replies)
Discussion started by: black_fender
5 Replies

3. Shell Programming and Scripting

Get number of elements in a list

Hi all I would like to know the number of elements in a list. $list=`ls xyz*` I want to get the number of files xyz* in the folder. Anybody please help!!! (5 Replies)
Discussion started by: VidyaVenugopal
5 Replies

4. UNIX for Dummies Questions & Answers

List certain file in a folder and make list

Hi, im having problem that frustate me today. there are list of file in a folder that i want to grab the folder /subject/items/ in this folder there are this file CREATE_SUBxxxx.xml UPDATE_SUBxxxx.xml DELETE_SUBxxxx.xml loginresponsexxxxx.xml core how can i grab all the file... (1 Reply)
Discussion started by: andrisetia
1 Replies

5. Shell Programming and Scripting

Number of elements in Word list

Hello everyone, can anyone let me know if there is a way to get the count of elements in a word list that I use for a for loop in the way: for single_result in $results ; do ....... I know I can increment a counter in my for loop, but would there be a way to know the total number of elements in... (4 Replies)
Discussion started by: gio001
4 Replies

6. Shell Programming and Scripting

Script to unorder an ordered list

Wondering if someone could help me with this in any scripting/programming language. I have a list of ordered IP addresses and I want to unorder them. So for example, if I had a file like this: 111.111.111.110 111.111.111.111 111.111.111.112 111.111.111.113 111.111.111.114 I would want to... (4 Replies)
Discussion started by: kerpm
4 Replies

7. Shell Programming and Scripting

retrive value from a file

hi i am new to shell scripting i have a properties file like hs=abc hs1=def hs2=ghi now i want to retrive each value and assign it to a variable like var1 = abc please help (7 Replies)
Discussion started by: satish@123
7 Replies

8. Shell Programming and Scripting

to retrive data that appear only once in a file.

hi, I need to get the list of functions that are used more than once in a file list. Thanks in advance (1 Reply)
Discussion started by: anibu
1 Replies

9. AIX

How to list mirrored elements? (pv, vg, lv)

Hello, How can I list mirrored elements, such as PV, VG or LV? (and others if applicable). On AIX 4.3.3 and 5.3.0. I tried the commands: lscfg|grep hd lspv lsvg lsvg -l (of each vg) lslv (and some options) But could not find what am I looking for. I saw a "number of copies", but I am... (4 Replies)
Discussion started by: cactux
4 Replies

10. Shell Programming and Scripting

help to retrive data from log file

hi i have following file. where i m trying to retrive data on latest date. let us say we are extracting data from this file for Jun 30 where date is highest date in log file. here i want to take output in other file from first line of Jun 30 to the end of file in short i want retrive... (5 Replies)
Discussion started by: d_swapneel14
5 Replies
Login or Register to Ask a Question