LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2012, 05:24 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
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/.*
??

Last edited by metallica1973; 01-11-2012 at 05:29 PM.
 
Old 01-11-2012, 06:35 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Did you try with the * removed ?

(edit)
Try:
Code:
find $home_dir -depth ! -name ".*" | grep -f include

Last edited by Cedrik; 01-11-2012 at 06:43 PM.
 
Old 01-12-2012, 09:09 AM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
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.

Last edited by metallica1973; 01-12-2012 at 09:14 AM.
 
Old 01-12-2012, 09:28 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
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...
 
Old 01-12-2012, 09:49 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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".
 
1 members found this post helpful.
Old 01-12-2012, 03:32 PM   #6
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
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?

Last edited by metallica1973; 01-12-2012 at 03:34 PM.
 
Old 01-12-2012, 04:17 PM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
The ntubski's suggestion doesn't work ?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync excluding hidden files? gonzojd7 Linux - Newbie 4 11-29-2018 09:02 AM
Find and excluding all hidden directories metallica1973 Linux - General 7 10-28-2011 04:47 PM
Excluding multiple directories flamingo_l Linux - Newbie 11 08-03-2010 03:45 AM
Excluding Hidden Files / Folders in Tarball carlosinfl Linux - General 2 05-22-2008 10:23 AM
excluding hidden directories when using tar djgerbavore Slackware 3 01-05-2006 03:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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