LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   find command (https://www.linuxquestions.org/questions/programming-9/find-command-536617/)

ovince 03-11-2007 03:54 PM

find command
 
hi all,

In dir1 and dir2 directories I have same subdirectories DH* like

--root
+ dir1
|
|
+ dir2


How to force find command to remove all "*.jpg" files (that are inside DH*) from root. This does not work

find DH* -type f -name "*.jpg" -exec rm {} \;

thanks
oliver

random0 03-11-2007 04:08 PM

Try this command:
Quote:

find -type f -name "DH*.jpg" -exec rm {} \;
Edit:
Sorry, misunderstood your post. In bash, the command that you posted should work as expected. Are you using another shell?

ovince 03-11-2007 04:40 PM

no response to this command ... nothing happens

cfaj 03-11-2007 05:08 PM

Quote:

Originally Posted by ovince
hi all,

In dir1 and dir2 directories I have same subdirectories DH* like

--root
+ dir1
|
|
+ dir2


How to force find command to remove all "*.jpg" files (that are inside DH*) from root. This does not work

find DH* -type f -name "*.jpg" -exec rm {} \;


What does "does not work" mean? Does it find any files? Does it find the directories you are trying to search? Remove '-exec rm {} \;' to see what files it does find, if any. Fix your command so that is finds the files, then put the rm command back.

This is probably closer to what you need:
Code:

find dir1/DH* dir2/DH* -type f -name "*.jpg" -exec rm {} +
If your version of find does not suport '+', replace it with '\;'.

ovince 03-12-2007 02:29 AM

yes thanks....it works

I read in man for find that regexp can be used but no example is given. google is also poor with examples. My guesing of how it should be writen does not work
(for example to -exec only files that begin with t)

find dir1/DH* dir2/DH* -type f -regex /^t/ -exec rm {} +

Could you provide me an example or two?

thanks

bigearsbilly 03-12-2007 03:38 AM

what's wrong with
rm dir?/DH*/*.jpg ???


All times are GMT -5. The time now is 03:44 PM.