LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2009, 01:21 PM   #1
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Rep: Reputation: 37
[bash] find -exec does not execute correctly...


Hi guys,

can somebody explain me why:

having a folder with

temp
+
+--->temp.ai
+--->temp.eps

Code:
find . -name "*.ai" -o -name "*.eps" -exec rm {} \;
ends up with:

temp
+
+--->temp.ai


the regex is actually working, but only for half of it... :S
 
Old 09-11-2009, 01:32 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You use an OR statement for the -name options, they need to be 'grouped'. This will solve the problem:

find . \( -name "*.ai" -o -name "*.eps" \) -exec ls {} \;

The ls is for testing, change to rm when you are happy.

Hope this helps.
 
Old 09-11-2009, 01:33 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Permissions? Try putting an echo in front of the rm to find out if find is issuing the commands.
 
Old 09-11-2009, 05:33 PM   #4
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by druuna View Post
Hi,

You use an OR statement for the -name options, they need to be 'grouped'. This will solve the problem:

find . \( -name "*.ai" -o -name "*.eps" \) -exec ls {} \;

The ls is for testing, change to rm when you are happy.

Hope this helps.
that did the trick... the confusion came because

Code:
find . -name "*.ai" -o -name "*.eps"
returns temp.ai AND temp.eps... so I thought it was logical to just add the -exec part but it seems to be that the exec only applies to the last expression... unless we group it like you pointed out (which I was not aware that had to be done).


Thanks for the help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
chroot: cannot execute /bin/sh: Exec format error jnojr Linux - General 8 06-24-2012 12:52 AM
how can I execute two commands on exec of a find? eantoranz Programming 3 08-03-2010 04:51 PM
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
How to execute multiple commands with find and -exec... tomstratton Linux - General 6 05-26-2009 03:26 AM
error in exec of stage2 trying to execute /usr/bin/runinstall2 Catherine Brett Linux - Newbie 0 07-11-2003 12:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration