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!

Find with two actions 4

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
US
Good Day,

I would like to run the find command and for each file found, I would like to run ls and cat.

I tried the following without much luck -
find . -name '*.data' -exec ls -ltr {}\; cat {} \;

Any ideas?

Regards,
Dan

 
Just add another -exec before the cat?

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

No luck with -
Code:
find . -name '*.data' -exec ls -ltr {}\; -exec cat {} \;

Regards,
Dan

 
How about...
Code:
find . -name '*.data' [b]-ls[/b] -exec cat {} \;

 
Beautiful thing Sam! Sorry, but why does it work?

Regards,
Dan
 
I see, -ls is a distinct ACTION, exactly as -exec command ;

Regards,
Dan
 
...but only with GNU find.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Ah, well.... must be a recent addition!

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
I have just given Feherke a star - his correction to the first suggestion works as expected. It's really easy to make a mistake and forget the space before the \; when using the find command.
 
Right, I missed it -- it works perfectly.

Regards,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top