LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux 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
 
Search this Thread
Old 09-16-2004, 03:56 AM   #1
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Rep: Reputation: 30
Using find and grep - how to exclude a result ?


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
 
Old 09-16-2004, 04:04 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
find / \( -type d -regex "/home/daniel" -prune \) -o -user daniel -print

Yves.
 
Old 09-16-2004, 04:06 AM   #3
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
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
 
Old 09-16-2004, 04:07 AM   #4
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

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

Graziano
 
Old 09-16-2004, 04:19 AM   #5
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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
 
Old 09-16-2004, 04:29 AM   #6
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
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
 
Old 09-16-2004, 04:33 AM   #7
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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 ...
 
Old 09-16-2004, 04:35 AM   #8
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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.
 
Old 09-16-2004, 04:36 AM   #9
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
no it doesn't work too , it shows also lines with /backup ...
 
Old 09-16-2004, 04:42 AM   #10
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
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 04:43 AM.
 
Old 09-16-2004, 04:45 AM   #11
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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 .
 
Old 09-16-2004, 04:49 AM   #12
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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
 
Old 06-29-2005, 09:47 AM   #13
mauricev
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Rep: Reputation: 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.
 
Old 12-04-2010, 10:02 PM   #14
bwachidotcom
LQ Newbie
 
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
<<<find / \( -type d -regex "/home/daniel" -prune \) -o -user daniel -print >>>
yes he got lucky.

the above expression means find /home/daniel, but do not traverse the directory tree, (which means /home/daniel will be added to the results) or (-o) find everything from user daniel

based on the origional question, i would do this
find / ! \( -wholename '/home/daniel*' -o -wholename /backup* -o -wholename /etc/etc/ifyouknowwhatimean \) -print

Last edited by bwachidotcom; 12-04-2010 at 10:04 PM.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] grep exclude Manuel-H Linux - General 4 10-12-2010 08:50 PM
ps -ef | grep iptables gives no result ? markraem Linux - Networking 1 07-07-2004 05:28 AM
How can I filter the output of grep to exclude certain cases? QtCoder Linux - General 1 03-28-2004 12:05 AM
how to grep within a script, and test result? bobbyr Programming 4 01-13-2004 12:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM


All times are GMT -5. The time now is 08:10 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