INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

ls - paths with two files

ls - paths with two files

(OP)

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
$ 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}
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.
$ 

RE: ls - paths with two files

(OP)

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
$ 

RE: ls - paths with two files

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
tgmlify - code syntax highlighting for your tek-tips posts

RE: ls - paths with two files

(OP)


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
$ 

RE: ls - paths with two files

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
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close