Operating System - HP-UX
1748122 Members
3392 Online
108758 Solutions
New Discussion юеВ

list certain files from another directory

 
bob the spod
Occasional Advisor

list certain files from another directory

whats the quickest way to list a bunch of files from another directory.

i.e. if I have done a 'cd' Im at my user level.
I now want to know if there are any files which start with fish dogs cats or mice in the /stage/intray directory....

quickest answer wins a virtual glass of red wine from bob the spods virtual wine cellar (which I am told is the best one in virtual city)

cheers!
bob
you make me feel like dancing (gonna dance the night away!)
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: list certain files from another directory

# ls /stage/intray/fish*
# ls /stage/intrag/dogs*
# ls /stage/intray/cats*
# ls /stage/intray/mice*

John Palmer
Honored Contributor

Re: list certain files from another directory

How about:

ls /stage/intray/fish*
ls /stage/intray/dogs*
etc...

Regards,
John
Darren Prior
Honored Contributor

Re: list certain files from another directory

Hi Bob,

ls -1 /stage/intray | grep -e ^fish -e ^dogs -e ^cat -e ^mice

You can use ls on any directory if you specify the directory you wish to view. The grep will only print lines that start with fish, dogs, cats, mice.

Further info on these commands is available in their respective man pages.

regards,

Darren.
Calm down. It's only ones and zeros...
Darren Prior
Honored Contributor

Re: list certain files from another directory

As an aside the forums work better on points rather than virtual wine - probably because people's taste in wine differs so much! ;)
Calm down. It's only ones and zeros...
Emiel van Grinsven
Valued Contributor

Re: list certain files from another directory

you can always add a path to ls

ls /stage/whatever

than grep for whatever you're looking for..

ls /stage/whatever |grep cats

Is this what you mean?
Steve Steel
Honored Contributor

Re: list certain files from another directory

Hi


cd dir

find $PWD|grep -e fish -e dogs -e mice -e cats


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Steve Steel
Honored Contributor

Re: list certain files from another directory

Hi


Got that wrong

cd dir

ls -1|grep -e dogs =e fish -e cats -e mice


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Robin Wakefield
Honored Contributor

Re: list certain files from another directory

Hi Bob,

Use find:

find /stage/intray \( -name "fish*" -o -name "dogs*" -o -name "cats*" -o -name "mice*" \) -type f

rgds, Robin