LinuxQuestions.org
Visit Jeremy's Blog.
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 10-27-2011, 10:41 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
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: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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: 193Reputation: 193
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
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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: 193Reputation: 193
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
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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,190

Original Poster
Rep: Reputation: 60
Gentlemen,

This actually worked:

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


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
rsync excluding hidden files? gonzojd7 Linux - Newbie 4 11-29-2018 09:02 AM
[SOLVED] Excluding directories with find metallica1973 Linux - General 4 06-13-2011 05:29 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

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

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