Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to generate a file list from a disk volume. Some of the directories (all hidden directories under the root directory) have strange permissions that causes find to complain.

I try to exclude all these paths, but one directory still complains:

find . -type f -not -path './.*/*'
find: ./.DocumentRevisions-V100: Permission denied

The rights are like this (set so by the operating system, so I assume they shouldn't be messed with).

d--x--x--x root  wheel   .DocumentRevisions-V100

How do I change the find statement to effectively omit all the hidden directories as to not complain. (I do not want to do 2>/dev/null as I want to know about other problems).

share|improve this question

2 Answers 2

The syntax of find is a strange beast indeed. I think you might have success with

find . -path './.*' -prune -o -type f -print

per the find(1) man page:

To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory 'src/emacs' and all files and directories under it, and print the names of the other files found, do something like this:

find . -path ./src/emacs -prune -o -print
share|improve this answer
    
Still complains about that one directory. Maybe because not even root have read permission? –  forthrin Aug 21 '13 at 15:04
    
I think you want -path './.*' (no trailing /*). –  cjm Aug 21 '13 at 15:05

With GNU find or any other find that supports the -readable and -executable predicates:

find . -type d ! -readable ! -executable -prune -o -type f -not -path './.*/*' -print

First we prune directories that aren't traversable. If that condition doesn't apply, try the other condition(s).

If your find doesn't have these options, you can match against the file permissions.

find . -type d ! -perm -u+rx -prune -o -type f -not -path './.*/*' -print
share|improve this answer
    
I don't have GNU find. Your suggestion still gives "Permission denied", but -perm is probably the thing. How do I rearrange the statement to make it work? –  forthrin Aug 23 '13 at 12:49
1  
@forthrin Oops, I had appended my conditions to yours which didn't make sense syntactically (resulting in -type f … -type d which matches nothing). Try now. –  Gilles Aug 23 '13 at 12:55
    
It works now! Perfect! –  forthrin Aug 23 '13 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.