Reply to comment
Find Tips/Tricks
Submitted by zhigang on Tue, 2008-03-18 14:24Common usage
$ find . -type d -exec chmod 755 {} \;
$ find . -type f -exec chmod 644 {} \;
Using Regular Expressions (regex)
If the "-name" option cannot satisfy your need, remember to use the "-regex" option, which offers more powerful parttern matching.
$ find . -regex pattern -print
"prune" option tricks
Note that:
$ find . -path '*/.zhigang' -prune -o -type f
is equivalent to:
$ find . \( -path '*/.zhigang' -prune -o -type f \) -print'
ie., "-print" is added at the outer level; but "-o" binds lower than "-a", thus:
$ find . -path '*/.zhigang' -prune -o -type f -print
is equivalent to:
$ find . -path '*/.zhigang' -prune -o \( -type f -print \)
Exclude some directories when finding files
$ find / \( -path '/usr' -o -path '/proc' \) -prune -o -name 'httpd.conf' -print
Use find to tar part of a tree only
If you are not worried about the tree structure including empty directories:
$ cd A; tar cvf - `find . -type f -print | grep -v B` | gzip > x.tar.Z
If you do want the full structure apart from B:
$ tar cvf - `find A/* -type d -print | grep -v B` | gzip > x.tar.Z
or use tar only:
$ tar cvf - --exclude| gzip -f - > tree.tar.gz
Find SUID/SGID commands
# find / \( -perm -004000 -o -perm -002000 \) -type f -print # find / \( -path '/nfs' -prune \) \( -perm -004000 -o -perm -002000 \) -type f -print # find / -xdev \( -perm -004000 -o -perm -002000 \) -type f -print
Be sure that you are the superuser when you run find, or you may miss SUID files hidden in protected directories.
- Add new comment
- 55 reads


Recent comments
15 weeks 4 days ago
40 weeks 4 days ago
47 weeks 1 day ago
49 weeks 5 days ago
1 year 1 week ago
1 year 49 weeks ago