查找特定目录并忽略其他
Find especific directory and ignore other
我需要在一台服务器上找到所有的 iplanets,我想使用这个命令:
find / type d -name https-* | uniq
但同时我需要忽略一些directories/file。我一直在尝试使用 !
,但它并不总是有效。我有这样的命令:
find / type d -name https-* ! -name https-admserv* ! -name conf_bk* ! -name alias* ! -name *db* ! -name ClassCache* | uniq
我需要忽略所有这些。目录 admserv
、conf_bk
、alias
和 tmp
以及文件 *.db*
基本上我需要找到这个:
/opt/mw/iplanet/https-daniel.com
/opt/https-daniel1.com
/apps/https-daniel2.com
我只需要找到目录名。我怎样才能忽略所有其他内容?
使用-prune
避免递归目录:
find / \( -type d \( -name 'https-admserv*' -o -name 'conf_bk*' -o -name 'alias*' -o -name 'tmp' \) -prune -o -type d -name 'https-*' -print
无需忽略任何文件。您只选择了 https-*
个目录,因此其他所有内容都将被忽略。
并且不需要通过管道传输到 uniq
,因为 find
永远不会产生重复项。
我需要在一台服务器上找到所有的 iplanets,我想使用这个命令:
find / type d -name https-* | uniq
但同时我需要忽略一些directories/file。我一直在尝试使用 !
,但它并不总是有效。我有这样的命令:
find / type d -name https-* ! -name https-admserv* ! -name conf_bk* ! -name alias* ! -name *db* ! -name ClassCache* | uniq
我需要忽略所有这些。目录 admserv
、conf_bk
、alias
和 tmp
以及文件 *.db*
基本上我需要找到这个:
/opt/mw/iplanet/https-daniel.com
/opt/https-daniel1.com
/apps/https-daniel2.com
我只需要找到目录名。我怎样才能忽略所有其他内容?
使用-prune
避免递归目录:
find / \( -type d \( -name 'https-admserv*' -o -name 'conf_bk*' -o -name 'alias*' -o -name 'tmp' \) -prune -o -type d -name 'https-*' -print
无需忽略任何文件。您只选择了 https-*
个目录,因此其他所有内容都将被忽略。
并且不需要通过管道传输到 uniq
,因为 find
永远不会产生重复项。