Wednesday, January 5, 2011

find command excludes specific directories with regular expression

find command excludes specific directories with regular expression

Method 1:
# find -E /www/drupal/sites/ -type d -mindepth 1 -maxdepth 1 -not -regex '.*/(.svn|all|dir1|dir2)' | xargs ls -ld

Method 2:
# find /www/drupal/sites/ -type f -not -path '*/.svn/*' -not -path '*/dir1'

Note: you need the -E option on FreeBSD. The -E option interprets regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE's). The re_format(7) manual page fully describes both formats.

Note: the trailing slash of a directory is necessary if the directory is a symbolic link (ex: /www/).

Reference:
what is the difference between find -exec cmd {} + and xargs

No comments: