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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ls - paths with two files 2

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL

hello,
is it possible to "ls" exact two files being in different directories with only one ls "parameter" - (if first example there are both files given/specified)

Code:
$ ls -al a/slib/file1 a/lib/file2
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:24 a/lib/file2
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:23 a/slib/file1
$ [red]ls -al a/*lib/{file1,file2}[/red]
ls: 0653-341 The file a/*lib/{file1,file2} does not exist.
$ ls -al a/*lib/[file1],[file2}
ls: 0653-341 The file a/*lib/[file1],[file2} does not exist.
$ ls -al a/*lib/[file1,file2}
ls: 0653-341 The file a/*lib/[file1,file2} does not exist.
$ ls -al a/*lib/(file1,file2)
ksh: 0403-057 Syntax error: `(' is not expected.
$ ls -al a/*lib/file1,file2
ls: 0653-341 The file a/*lib/file1,file2 does not exist.
$
 

of course when I specify * at the end I get all files (so too many that I expected to get - only two of them file1 and file2 are expected)

Code:
$ ls -al a/*lib/*
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:24 a/lib/file2
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:33 a/lib/file3
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:33 a/lib/file4
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:23 a/slib/file1
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:33 a/slib/file5
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:33 a/slib/file6
$
 
What about this ?
ls -al a/*lib/file[12]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or if the actual filenames are more complex than the example you gave, this syntax may work depending on your shell (should work in ksh or bash with shopt -s extglob enabled):

Code:
ls -al a/*lib/?(filefoo|filebar)

#or

ls -al a/*lib/file?(foo|bar)

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 


thx. the first Annihillanic's way is universal (not only for file[12]):

Code:
$ ls -al a/*lib/?(file2|try)
-rw-r--r--    1 aaaa  bbbb              0 Aug 31 14:24 a/lib/file2
-rw-r--r--    1 aaaa  bbbb              0 Sep 03 07:09 a/lib/try
-rw-r--r--    1 aaaa  bbbb              0 Sep 03 07:13 a/slib/try2
$
 
Strange, I can't reproduce that. What OS, shell and versions?

Code:
$ find a -ls
1654807    4 drwxr-xr-x   4 user group       4096 Sep  3 17:18 a
1654800    4 drwxr-xr-x   2 user group       4096 Sep  3 17:17 a/slib
1654806    0 -rw-r--r--   1 user group          0 Sep  3 17:17 a/slib/try2
1654805    0 -rw-r--r--   1 user group          0 Sep  3 17:17 a/slib/try1
1654798    4 drwxr-xr-x   2 user group       4096 Sep  3 17:17 a/lib
1654801    0 -rw-r--r--   1 user group          0 Sep  3 17:17 a/lib/file1
1654802    0 -rw-r--r--   1 user group          0 Sep  3 17:17 a/lib/file2
1654803    0 -rw-r--r--   1 user group          0 Sep  3 17:17 a/lib/file3
1654804    0 -rw-r--r--   1 user group          0 Sep  3 17:17 a/lib/try
$ ls -al a/*lib/?(file2|try)
-rw-r--r-- 1 user group 0 Sep  3 17:17 a/lib/file2
-rw-r--r-- 1 user group 0 Sep  3 17:17 a/lib/try
$

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