LinuxQuestions.org
Register a domain and help support LQ
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 10-27-2011, 10:41 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,113

Rep: Reputation: 57
Find and excluding all hidden directories


How can I exclude all hidden directories from everyones home directories when using find:


Code:
find /home -depth -path '*/.*' -prune -o -print
cd /home
find . -depth \( -wholename \./*/\.\* \) -prune -o -print
find . -depth ! -path "./*/.*" -print
find . -depth \( path './*/.*' -o -prune -print \)
find . -depth ! \(  -path './*/.*' -o -prune -print \)
I want to remove all ".*" hidden junk from all the home directories:

/home/user1/.*
/home/user2/.*
/home/user3/.*

?????????????
 
Old 10-28-2011, 12:33 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,431
Blog Entries: 33

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Code:
find . -not -path '*/.*/*' -not -name '.*'
This excludes both the contents of hidden directories (-not -path) and hidden files (-not -name). -not and ! are interchangeable.

Sample:
./some/path/is/here/filename

-not -path works on the whole ./some/path/is/here/filename
-not -name works on filename only.

If you want to see other find tricks I list some in my LQ blog.

SAM

Last edited by sag47; 10-28-2011 at 01:37 PM.
 
Old 10-28-2011, 12:43 AM   #3
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 189Reputation: 189
Quote:
Originally Posted by metallica1973 View Post
How can I exclude all hidden directories from everyones home directories when using find:
Quote:
Originally Posted by metallica1973 View Post
I want to remove all ".*" hidden junk from all the home directories:
Not exactally which you are trying to do...

but to do the latter
Code:
find /home/ -name \.\* | xargs rm -r
should do the trick...

(i left the -f out for safety, but you may want to include it)
 
Old 10-28-2011, 12:52 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The OP doesn't want to delete all hidden directories. That would delete everyone's desktop settings.

---

Sometimes it is better to use the pattern ".[^.]*" instead of ".*" to prevent ".." from matching.

Last edited by jschiwal; 10-28-2011 at 12:54 AM.
 
Old 10-28-2011, 01:13 AM   #5
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 189Reputation: 189
Quote:
I want to remove all ".*" hidden junk from all the home directories:

/home/user1/.*
/home/user2/.*
/home/user3/.*
I guess I misread that then....
 
Old 10-28-2011, 07:25 AM   #6
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The OP wants to remove the hidden junk from the find results, not remove the files themselves.
 
Old 10-28-2011, 01:34 PM   #7
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,431
Blog Entries: 33

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Quote:
Originally Posted by jschiwal View Post
Sometimes it is better to use the pattern ".[^.]*" instead of ".*" to prevent ".." from matching.
There is no need to do that for the '..' hard link. find will never enter that directory. See the -noleaf option of the find man pages. My solution in the first post does what the OP wants to do.

SAM

Last edited by sag47; 10-28-2011 at 01:36 PM.
 
Old 10-28-2011, 04:47 PM   #8
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,113

Original Poster
Rep: Reputation: 57
Gentlemen,

This actually worked:

Code:
find /home -depth ! -path "*/\.*"
Many thanks for the comments
 
1 members found this post helpful.
  


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] Excluding directories with find metallica1973 Linux - General 4 06-13-2011 05:29 AM
rsync excluding hidden files? gonzojd7 Linux - Newbie 2 09-05-2008 10:47 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
Find excluding multiple directories with a wildcard pteigeler Linux - Software 1 09-02-2005 10:57 AM


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