Languages and Scripting

omit hidden directories on a find

 
SOLVED
Go to solution
Scott Lindstrom_2
Regular Advisor

omit hidden directories on a find

I am setting up an rsync process and want to omit hidden files and hidden directories from the file list. I can omit hidden files by using this in the find command:

find . ! -name ".*" -type f

This will skip files like:

./myid/.cshrc
./myid/.exrc
./myid/.login
./myid/.profile
./myid/.sh_history


But hidden directories like this still slip through:

./myid/.ssh/known_hosts

I have not been able to find the proper pattern to use in a 'grep -v' to add after the find to omit any . directory. Any ideas?

Scott
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: omit hidden directories on a find

Hi Scott:

This is expected. The '-name' argument applies to the *basename* of the path travesed. Thus only the *file* (not the heirarchal patch) is considered.

Therefore:

# -type f ! -path "*.*" -print

...should solve your problem.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: omit hidden directories on a find

Hi (again) Scott:

Oops:

# find /path -type f ! -path "*.*" -print

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor
Solution

Re: omit hidden directories on a find

>JRF: find /path -type f ! -path "*.*"

You probably want something that will still return foo.c: :-)
find /path -type f ! -path "*/.*"
Scott Lindstrom_2
Regular Advisor

Re: omit hidden directories on a find

James - yours was 99% there but it omitted any file with a dot in it.

Dennis - thanks for your solution - this looks like it's going to work great!

Scott