比方说,我有像这样如何使用-not in find?
mkdir -p test/1
mkdir -p test/2
mkdir -p test/3
touch test/1/touch
touch test/2/touch
touch test/3/touch
如何发现除了那些在test/2
test/
所有文件的目录结构?
比方说,我有像这样如何使用-not in find?
mkdir -p test/1
mkdir -p test/2
mkdir -p test/3
touch test/1/touch
touch test/2/touch
touch test/3/touch
如何发现除了那些在test/2
test/
所有文件的目录结构?
另一个短发现变种完成这件事是:
find test ! -path "test/2*"
输出
test
test/1
test/1/touch
test/3
test/3/touch
使用-prune
:
find test -path 'test/2' -prune -or -print
这对我很有用,但你能解释一下吗?我个人在'find'遇到了麻烦,为什么有时这样的东西('-or -print')有时会起作用... – 2012-01-05 14:39:11
@DanFego:恐怕我不能写一个比'' - 修剪''例子在'查找'手册页。 – thiton 2012-01-05 14:42:19
Ohhhhhhh它只是打我。如果路径是“test/2”,那么它是“真的&&真的||” print',在这种情况下'print'不会发生?否则它是'false && true ||打印“,在这种情况下它可以。 – 2012-01-05 14:45:03
有一些good examples here的目录排除在搜索时。
您可以使用-not
这样:
find -not -wholename './test/2*'
这不会显示''。test/20''及其子目录。 – 2012-01-05 14:40:18
@DanFego:是的。如果有超过9个子目录,则应命名为01,02 ... :-) – choroba 2012-01-05 14:41:19
touche!虽然然后有人会找到这个,并开始一个关于如何重命名所有目录的问题。 :P – 2012-01-05 14:42:25
可能是一个更好适合Serverfault或UNIX和Linux。 – 2012-01-05 14:34:52