Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi, can I tell to "ls" to list f 2

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

hi,
can I tell to "ls" to list files in the order they were given on the parameter list?

I mean instead of:
Code:
$ ls -al list_1 list_2 list_10
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_1
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_10
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_2

get:
Code:
$ ls -al list_1 list_2 list_10
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_1
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_2
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_10
$

until now I need to sort it like:
Code:
$ ls -al list_1 list_2 list_10|sort -n -t _ -k 2,2
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_1
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_2
-rw-r--r--    1 userx  staff              0 Nov 19 19:18 list_10
$

can the sort (or any other extra) command be omited and use "some" embedded ls feature to achieve this?
 
What about this ?
ls -al list_1; ls -al list_2; ls -al list_10

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If they were created in the correct order chronologically, you can use "-tr" to sort them by time.

Code:
$ touch list_1
$ touch list_2
$ touch list_10
$ ls -l list_*
-rw-r--r--   1 userx    staff          0 Nov 21 13:36 list_1
-rw-r--r--   1 userx    staff          0 Nov 21 13:36 list_10
-rw-r--r--   1 userx    staff          0 Nov 21 13:36 list_2
$ ls -ltr list_*
-rw-r--r--   1 userx    staff          0 Nov 21 13:36 list_1
-rw-r--r--   1 userx    staff          0 Nov 21 13:36 list_2
-rw-r--r--   1 userx    staff          0 Nov 21 13:36 list_10



 
On what OS? On Linux you can use ls -U to do this. I think this is a GNU extension... at least it's not available on HP-UX, I haven't looked on any other OS.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top