ls all files in sequence. How to?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls all files in sequence. How to?
# 1  
Old 05-09-2010
ls all files in sequence. How to?

Hi, all:

Newbie questions:


For example, if I have 6 files, respectively named as:
Quote:
1.txt
2.txt
3.txt
10.txt
11.txt
20.txt
How to "ls" all files in sequence of two ways?

1) The first way is according to the sequence of the natural number.
Say, the same sequence as shown as they are given.

2) The second way is default Linux way. My "ls" directly gives:
Code:
jiapei@jiapei-laptop:~/Desktop/test$ ls
10.txt  11.txt  1.txt  20.txt  2.txt  3.txt


Some times, we may need the 2nd way to display all files, but most of the times, we will go for the 1st way to display all files. My question is just "how to"?

Cheers
JIA
# 2  
Old 05-09-2010
Code:
$ ls | sort -nt. -k1,1    
1.txt
2.txt
3.txt
10.txt
11.txt
20.txt

# 3  
Old 05-09-2010
Thank you, but what does

Code:
k1,1

mean?
and why
Code:
-nt.

??

I tried

Code:
ls | sort -n

it works already.

Quote:
Originally Posted by alister
Code:
$ ls | sort -nt. -k1,1    
1.txt
2.txt
3.txt
10.txt
11.txt
20.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this: aasdsaffsc23 scdsfsddvf46567 mionome0001.pdb asdsdvcxvds dsfdvcvc2324w What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have : nomefile0001.txt that must... (10 Replies)
Discussion started by: danyz84
10 Replies

2. Shell Programming and Scripting

Add sequence number to files

Hi I am having files in my dir ,some times it vary ,i need to assign sequence number with gunzip the file name .Please advise ex: file1.gz file1111.gz file11111.gz file1111111.gz expecting out output file_1 file1111_2 file1111111_3 i written this script ,its not working what i... (3 Replies)
Discussion started by: mohan705
3 Replies

3. Shell Programming and Scripting

Case script to get missing sequence among files

I want to use case statement to find the range of missing sequence in my directory which it has some few ( dat & DAT ) files my directory /home/arm/my_folder/20130428 contains : f01_201304280000.DAT f01_201304280001.DAT f01_201304280003.DAT f02_201304280000.dat f02_201304280002.dat... (2 Replies)
Discussion started by: arm
2 Replies

4. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

5. Shell Programming and Scripting

New sequence nos to be added in new files

Hi All, Please help me in below request. Got multiple files in a dir ex: /os . from each file need to filter based upon first field (field only has 1,2,3 or 4) and then put it in different files based on the Field 1. But need to generate a sequence while inserting and the sequence number needs... (1 Reply)
Discussion started by: rdakshn
1 Replies

6. Shell Programming and Scripting

print out missing files in a sequence

Hello all, I have several directories with a sequence of files like this IM-0001-0001.dcm IM-0001-0002.dcm IM-0001-0003.dcm IM-0001-0004.dcm IM-0001-0005.dcm I would like to print out the name of the file that is missing. I currently have the following ineffecient way to do this... (4 Replies)
Discussion started by: avatar_007
4 Replies

7. Shell Programming and Scripting

perl merge two files by the time sequence

Hi Guys, i have two files: fileA: 20090611 00:00:11 20090611 00:00:11 20090611 00:00:24 20090611 00:01:10 20090611 07:13:00 fileB: 20090611 00:00:01 20090611 00:00:12 20090611 00:00:24 20090611 00:01:12 20090611 09:13:00 want to make two files into a single file, but follow the... (14 Replies)
Discussion started by: jimmy_y
14 Replies

8. Shell Programming and Scripting

script to touch a sequence of files

Hi, My requirement is i need to touch a sequence of files like touch a touch b touch c now i need the script in a way that checks if all files are touched or not. if any file say b is not touched then i should get this notification. Please suggest as i am new to unix (2 Replies)
Discussion started by: sussane
2 Replies

9. UNIX for Dummies Questions & Answers

Rename Files in sequence

I have a bunch of files below in some directory /home/tmp: abc.txt def.txt ghi.txt And I want to rename them with sequence as their extension (in the format 00# see below): abc.001 def.002 ghi.003 I need some help with this and below is a basic code structure to get... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

10. Shell Programming and Scripting

Delete all files up to a sequence

All, Please can you help me with this ? I have a requirement to compress the files older than a sequence number. Say the directory has the following files a_101 a_102 a_103 a_104 a_105 a_106 a_107 a_108 I would like to compress all files based on a number i supply. IE. if i... (10 Replies)
Discussion started by: kamathg
10 Replies
Login or Register to Ask a Question