LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-16-2004, 01:49 AM   #1
ebasi
Member
 
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
exclude directory from find


i would like to find some files in my system but I don't know how to exclude some directories from this search

example:
find /data/ -iname "*.mp3" -or -iname "*.mpg" -or -iname "*.avi" -or -iname "*.exe" -or -iname "*.mpeg" -or -iname "*.asf" -or -iname "*.wmv" -or -iname "*.wma" -type f

I don't want to search in /data/download/
Help me please!
 
Old 07-16-2004, 01:58 AM   #2
free_ouyo
Member
 
Registered: Mar 2004
Location: Belgium
Distribution: Ubuntu
Posts: 133

Rep: Reputation: 15
Re:find

Hello,

You can use the grep command like :

find /data/ -iname "*.mp3" -or ... "*.wma" -type f | grep -v "^/data/download/"

Hope this help

Free_ouyo
 
Old 07-16-2004, 02:05 AM   #3
ebasi
Member
 
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
Thanks a lot, it's fine!!!
 
Old 07-16-2004, 02:08 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Code:
man find
/-path
Speaks for itself ... look at the prune within that section


Code:
man find
/OPERATORS
That suggests that the whole lot probably doesn't quite do
what you want in the first place ...
You want to seperate them with , not with -or ....



Cheers,
Tink
 
Old 07-16-2004, 02:11 AM   #5
ebasi
Member
 
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
I wanna remove the files

find /data/docs-clients/ -iname "*.mp3" -or -iname "*.mpg" -or -iname "*.avi" -type f -exec rm {}
some like this
but i don't want to remove the files from /data/download/ directory

Last edited by ebasi; 07-16-2004 at 03:24 AM.
 
Old 07-16-2004, 09:32 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
I was hoping my quoting of "man find" would make
you read it - I guess I was wrong :}

Try something like:
Code:
 
find /data -type f -path '*/data/download/*' -prune -iname "*.mp3", -iname "*.mpg", -iname "*.avi", -iname "*.exe", -iname "*.mpeg", -iname "*.asf", -iname "*.wmv", -iname "*.wma"
I wouldn't suggest going to rm right away ;) ... check whether
it finds all you need first.


Cheers,
Tink
 
Old 07-16-2004, 10:40 PM   #7
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi ebasi,
You may use the regex option of the find. For a negation you must use the not expression. In your example, add in your line \( ! -regex '/data/download/.*' \). You also have to put all that "or" expression into parenthesis because you want all the masks which are of type f. So, your expression would be
Code:
find /data/ \(  -iname "*.mp3" -or -iname "*.mpg" -or -iname "*.avi" -or -iname "*.exe" -or -iname "*.mpeg" -or -iname "*.asf" -or -iname "*.wmv" -or -iname "*.wma" \) -type f \( ! -regex '/data/download/.*' \)
I recommend you to read the man page for find.

Good luck.
 
Old 07-17-2004, 02:02 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally posted by osvaldomarques
Code:
find /data/ \(  -iname "*.mp3" -or -iname "*.mpg" -or -iname "*.avi" -or -iname "*.exe" -or -iname "*.mpeg" -or -iname "*.asf" -or -iname "*.wmv" -or -iname "*.wma" \) -type f \( ! -regex '/data/download/.*' \)
Thanks Osvaldo, I learnt something today, and not only
to take my own advice :)


Cheers,
Tink
 
Old 07-17-2004, 02:12 AM   #9
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi Tinkster,

Every day we learn something. You're welcome!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Using find and grep - how to exclude a result ? graziano1968 Linux - General 13 12-04-2010 10:02 PM
exclude directory with cp hampel Linux - Software 3 06-04-2009 11:59 AM
tar --exclude --exclude-from cefn Linux - Software 4 10-11-2005 07:31 PM
How can I exclude NFS with find with no visit david.dales Linux - General 2 08-24-2005 03:08 AM
How to find a string in a directory? iclinux Linux - Newbie 2 07-02-2005 08:20 AM


All times are GMT -5. The time now is 03:11 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration