LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GREP Excluding Hidden Directories from being scanned (https://www.linuxquestions.org/questions/programming-9/grep-excluding-hidden-directories-from-being-scanned-923331/)

metallica1973 01-11-2012 05:24 PM

GREP Excluding Hidden Directories from being scanned
 
I wrote a script in Bash and have a line where is does a find and includes the directories that I want and excludes the directories that I dont.

Code:

find $home_dir -depth | grep -f include | grep -v -f exclude
All works fine but when I attempt to add the directory where I want to avoid being backed up (space constraints), it either blocks everything from being copied or doesnt work in excluding the hidden directories. This is the statement that I am adding to the exclude file:

Code:

/home/testuser/.*
??

Cedrik 01-11-2012 06:35 PM

Did you try with the * removed ?

(edit)
Try:
Code:

find $home_dir -depth ! -name ".*" | grep -f include

metallica1973 01-12-2012 09:09 AM

thanks for the reply,

I can successfully use:

Code:

find $home_dir -depth ! -path '*\/.*"| grep -f include | grep -v -f exclude
which works great but I would like to control everything from a exclude file. So inside of the exclude file, I have attempted:

Code:

*\/.*
.*
/home/testuser/*\/.*

but without success. I am using this inside of a bash shell script and when I attempt to use:

Code:

find $home_dir -depth ! -path '*\/.*"| grep -f include | grep -v -f exclude
but my logging goes crazy thought is works well. I would like to control what I need to exclude via an exclusion file and in this case, the "exclude". My goal is to exclude all of the hidden directories from my search.

Cedrik 01-12-2012 09:28 AM

In this case, I would just update the exclude file before, with
Code:

find $home_dir -type d -name ".*" >> exclude
Then process with the find line:
Code:

find $home_dir -depth | grep -f include | grep -v -f exclude...

ntubski 01-12-2012 09:49 AM

grep uses regular expressions, find -name uses glob patterns. To exclude hidden files with regexps use:
Code:

/\.
Which means "slash followed by dot", the dot has to be escaped because it normally means "any character".

metallica1973 01-12-2012 03:32 PM

Awesome stuff,

I ended doing this and all worked like a charm

Code:

find /home/testuser -maxdepth 1 -type f -name ".*" >> /home/testuser/exclude
to find the hidden files and

Code:

find /home/testuser -depth  -type d -name ".*" >> /home/testuser/exclude
for the directories. Is there a way to just put a oneliner in "/home/testuser/exclude" that will exclude all hidden files and or directories instead of putting each hidden file and directories inside of the file itself?

Cedrik 01-12-2012 04:17 PM

The ntubski's suggestion doesn't work ?


All times are GMT -5. The time now is 09:08 AM.