LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Thread Tools
Old 09-16-2004, 04:56 AM   #1
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0
Using find and grep - how to exclude a result ?


[Log in to get rid of this advertisement]
Hello

I am searching all files created from user "daniel" using

find / -user daniel

but I wish to remove/exclude from results all lines containing /home/daniel

Is it possible adding a grep command ? Or any other way ?

Thank you
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:04 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: Nantes (France)
Distribution: Mandriva 2009
Posts: 1,831
Thanked: 16
find / \( -type d -regex "/home/daniel" -prune \) -o -user daniel -print

Yves.
theYinYeti is offline     Reply With Quote
Old 09-16-2004, 05:06 AM   #3
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555
Thanked: 0
Hi Daniel (if that's your real name). Welcome to LinuxQuestions!

The -v flag to grep inverts your search. Grep output can be sent to another grep for further filtering. So, to find all files with a name containing martin excluding /home/daniel, you would write
# find / -user daniel | grep -v /home/daniel | grep martin

Martin
MartinN is offline     Reply With Quote
Old 09-16-2004, 05:07 AM   #4
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
Thank you , I was not expecting a so fast reply , thank you all !

Graziano
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:19 AM   #5
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
Quote:
Originally posted by theYinYeti
find / \( -type d -regex "/home/daniel" -prune \) -o -user daniel -print

Yves.
this solution is interesting because it doesn't use grep -v (so probably it uses less cpu and it's more fast) .

But suppose I wish to exclude from search more parameters , for example
"/home/daniel" and "/backup) ...

I tried

find / \( -type d -regex "/home/daniel" -prune \) \( -type d -regex "/backup" -prune \) -o -user daniel -print

find / \( -type d -regex "/home/daniel" | "/backup" -prune \) -o -user daniel -print

and other ways .. but no solution . Is it possible to exclude multiple values with find ?

Thank you
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:29 AM   #6
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555
Thanked: 0
This is maybe not the answer to your question, but might be valid anyway. If you search with 'find' and 'grep', I don't think that the CPU but the disk transfer speed is what's holding you back. Just listen to the poor HDD when you use find!

Martin
MartinN is offline     Reply With Quote
Old 09-16-2004, 05:33 AM   #7
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
infact my idle goes to 0 and IOwait near 99%

I suppose there is no way to limit .. I tried to renice but no useful ...
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:35 AM   #8
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
however using find with multimple exclusion should be

find / \( -type d -regex "/home/daniel" -prune -regex "/backup" -prune \) -o -user daniel -print

I tried it now and as it seems works fine.
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:36 AM   #9
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
no it doesn't work too , it shows also lines with /backup ...
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:42 AM   #10
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: Nantes (France)
Distribution: Mandriva 2009
Posts: 1,831
Thanked: 16
I can't test, but I would try one of those:

find / \( -type d -regex "/home/daniel" -prune \) -o \( -type d -regex "/backup" -prune \) -o -user daniel -print

find / \( -type d -regex '\(/home/daniel\)\|\(/backup\)' -prune \) -o -user daniel -print

Yves.

Last edited by theYinYeti; 09-16-2004 at 05:43 AM..
theYinYeti is offline     Reply With Quote
Old 09-16-2004, 05:45 AM   #11
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
Quote:
Originally posted by theYinYeti
I can't test, but I would try one of those:

find / \( -type d -regex "/home/daniel" -prune \) -o \( -type d -regex "/backup" -prune \) -o -user daniel -print

find / \( -type d -regex '\(/home/daniel\)\|\(/backup\)' -prune \) -o -user daniel -print

Yves.
Thank you , I am testing the 2th just now .
graziano1968 is offline     Reply With Quote
Old 09-16-2004, 05:49 AM   #12
graziano1968
Member
 
Registered: Sep 2004
Posts: 172
Thanked: 0

Original Poster
find / \( -type d -regex '\(/home/daniel\)\|\(/backup\)' -prune \) -o -user daniel -print

works great . It seems faster than find / -user daniel | grep -v '/home/daniel' | grep -v '/backup'

Thank you
graziano1968 is offline     Reply With Quote
Old 06-29-2005, 10:47 AM   #13
mauricev
LQ Newbie
 
Registered: Jun 2005
Posts: 3
Thanked: 0
I think you got lucky.

What happens if you reverse the order of the arguments?

find / -user daniel -o \( -type d -regex '\(/home/daniel\)\|\(/backup\)' -prune \) -print

I think it will return no results. If that is the case, then I'm baffled as to what's going on.
mauricev is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
ps -ef | grep iptables gives no result ? markraem Linux - Networking 1 07-07-2004 06:28 AM
How can I filter the output of grep to exclude certain cases? QtCoder Linux - General 1 03-28-2004 01:05 AM
how to grep within a script, and test result? bobbyr Programming 4 01-13-2004 01:11 PM
grep exclude Manuel-H Linux - General 2 11-21-2003 06:15 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 05:43 PM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration