LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-11-2007, 03:54 PM   #1
ovince
Member
 
Registered: Mar 2007
Posts: 77

Rep: Reputation: 15
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
 
Old 03-11-2007, 04:08 PM   #2
random0
LQ Newbie
 
Registered: Jun 2006
Location: Gainesville, Fl, USA
Distribution: Debian GNU/Linux
Posts: 18

Rep: Reputation: 0
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?

Last edited by random0; 03-11-2007 at 04:13 PM.
 
Old 03-11-2007, 04:40 PM   #3
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
no response to this command ... nothing happens
 
Old 03-11-2007, 05:08 PM   #4
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
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 '\;'.
 
Old 03-12-2007, 02:29 AM   #5
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
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
 
Old 03-12-2007, 03:38 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
what's wrong with
rm dir?/DH*/*.jpg ???
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Best Find Command ckoniecny Linux - General 16 02-15-2006 11:34 AM
`find' command cdnsupra Linux - Newbie 4 12-18-2005 11:13 AM
who to use find command NalinA Linux - Newbie 2 10-25-2005 08:08 AM
What is the FIND command Mic Q SUSE / openSUSE 1 04-07-2005 09:08 AM

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

All times are GMT -5. The time now is 04:27 AM.

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