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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-16-2004, 01:49 AM
|
#1
|
|
Member
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49
Rep:
|
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!
|
|
|
|
07-16-2004, 01:58 AM
|
#2
|
|
Member
Registered: Mar 2004
Location: Belgium
Distribution: Ubuntu
Posts: 133
Rep:
|
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
|
|
|
|
07-16-2004, 02:05 AM
|
#3
|
|
Member
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49
Original Poster
Rep:
|
Thanks a lot, it's fine!!!
|
|
|
|
07-16-2004, 02:08 AM
|
#4
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
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
|
|
|
|
07-16-2004, 02:11 AM
|
#5
|
|
Member
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49
Original Poster
Rep:
|
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.
|
|
|
|
07-16-2004, 09:32 PM
|
#6
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
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
|
|
|
|
07-16-2004, 10:40 PM
|
#7
|
|
Member
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519
Rep:
|
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.
|
|
|
|
07-17-2004, 02:02 AM
|
#8
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
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
|
|
|
|
07-17-2004, 02:12 AM
|
#9
|
|
Member
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519
Rep:
|
Hi Tinkster,
Every day we learn something. You're welcome!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:21 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|