LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 08-22-2014, 11:10 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
Find dont exclude folder


in my bash script i have this command:

Quote:
/bin/nice -n 19 /usr/bin/ionice -c2 -n7 find $wheretosearch -type f -size -800k -mmin -1440 ! -path "*backup*" ! -path "*/sys/*" ! -path "*/usr*" ! -path "*/proc/*" ! -path "*/task/*" -exec grep -l "$phrasse" {} \; >> $outputfile
as you see im trying to exclude folders like "proc" and "task" from the search, but when i execute script, it returns things like:

Quote:
find: /vz/root/240/proc/15889/task/15976: No such file or directory
find: /vz/root/240/proc/15889/task/16070: No such file or directory
find: /vz/root/240/proc/15889/task/16092: No such file or directory
find: /vz/root/240/proc/15889/task/16105: No such file or directory
find: /vz/root/1140/proc/1/task/1: No such file or directory
find: /vz/root/1140/proc/1170/task/1170: No such file or directory
find: /vz/root/1140/proc/1437/task/1437: No such file or directory
But when i exclude "sys" folder same way as proc, it woks to be excluded, but proc still showup

so im asking what is wrong on that command? thx
 
Old 08-22-2014, 12:37 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
That's part of how find does its thing. To get rid of the errors, just redirect them with:

Quote:
2>/dev/null
 
Old 08-22-2014, 12:53 PM   #3
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
thx, but kindly please tell me why find dont skip that folders. my aim is to decrease server load by skipping that folders, how i can make find to skip folder and dont waste time by working with it?
 
Old 08-22-2014, 01:02 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Ah. If you want to actually 'ignore' the directories and everything under it, you'll need to use 'prune' as find is not smart enough to NOT delve into an ignored directory.
 
Old 08-22-2014, 01:04 PM   #5
nmo
LQ Newbie
 
Registered: Jul 2014
Distribution: Debian
Posts: 21

Rep: Reputation: 8
I think the find option you are looking for is -prune. To my understanding the "not path" does not exclude the way that "prune" does.
 
Old 08-23-2014, 04:51 AM   #6
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Thanks for an advice, i modiffied the command to contain "-prune" instead, please is this correct?

Quote:
/bin/nice -n 19 /usr/bin/ionice -c2 -n7 find $wheretosearch -type d -name proc -prune -o -path "*proc*" -prune -o -path "*backup*" -prune -o -path "*/usr*" -prune -o -path "*/sys/*" -prune -o -size -800k -mmin -1440 -exec grep -l "$phrasse" {} \; >> $outputfile
the command should output last 24 hours modiffied files containing $phrasse into file $outputfile ..
 
Old 08-23-2014, 08:11 PM   #7
nmo
LQ Newbie
 
Registered: Jul 2014
Distribution: Debian
Posts: 21

Rep: Reputation: 8
Quote:
Originally Posted by postcd View Post
Thanks for an advice, i modiffied the command to contain "-prune" instead, please is this correct?



the command should output last 24 hours modiffied files containing $phrasse into file $outputfile ..

I believe prune is more of an action, like -print is. So it comes after what you want to prune. For example:

Quote:
find [path] [stuff to prune] -prune
Quote:
find / -type d -path "/proc" -prune
I'm not sure that you need as many pattern matches either, with the *word*. But of course I don't know your file system, or the exact purpose of your find. But I say, use what was discussed here, play around with the output and see if it meets your needs. I also would say to many try a few conditions manually, make sure they do what you want, then tie them together into your script.
 
Old 08-23-2014, 09:24 PM   #8
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,374

Rep: Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752
If you had thought about the information provided in your other thread http://www.linuxquestions.org/questi...es-4175515772/
then you might have realised that you will do better by grouping what you want to prune into a single expression
Code:
find $wheretosearch \( -path "*proc*" -o -path "*backup*" -o -path "*/usr*" -o -path "*/sys/*" \) -prune
 -o \( -size -800k -mmin -1440 \) -exec grep -l "$phrasse" {} \;

Last edited by allend; 08-23-2014 at 09:29 PM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
TAR Exclude everything in folder except this folder rationalthinker1 Linux - Newbie 5 04-30-2012 08:20 PM
Exclude a folder from a recursive delete? raz230 Linux - General 6 12-23-2011 01:57 PM
Using Find with an exclude/exclude file metallica1973 Linux - General 8 11-06-2011 09:39 PM
"find" exclude file/folder from search da1 *BSD 3 04-12-2009 04:08 PM
TAR: Unpack file, exclude a folder Smeerbalg Linux - Software 1 01-29-2006 07:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:22 PM.

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