How to exclude a list of full directory paths in find command on Solaris

爷,独闯天下 提交于 2019-12-03 16:19:37

You can't match files by full path with Solaris find, but you can match files by inode. So use ls -i to generate a list of inodes to prune, then call find. This assumes that there aren't so many directories you want to prune that you'd go over the command line length limit.

inode_matches=$(ls -bdi /opt/dir1 /opt/dir2 /var/dir3/dir4 |
                sed -e 's/ *\([0-9][0-9]*\) .*/-inum \1 -o/')
find / -xdev \( $inode_matches -nouser -o -nogroup \) -prune -o -print

An alternative approach would be to use a Perl or Python script and roll your own directory traversal. Perl ships with a find2perl script that can get you started with the File::Find module. In Python, see the walk function in the os.path module.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!