英文:
find listing pruned folder when searching using -newer argument
问题
$ tree -D
.
├── [Jun 25 18:46] dir1
│ └── [Jun 25 18:51] file1
└── [Jun 25 17:59] dir2
└── [Jun 25 18:46] file2
2 directories, 2 files
$ ls -l /tmp/since
-rw-r--r-- 1 xxx None 0 Jun 25 18:45 /tmp/since
这不清楚,为什么正确排除了 dir1 文件夹
$ find . -name dir1 -prune -o -type f -print
./dir2/file2
在上述命令中,为什么会出现以下命令中的 dir1 文件夹
$ find . -name dir1 -prune -o -type f -newer /tmp/since
./dir1
./dir2/file2
如何重新编写上述 find 命令,以仅列出自从文件 /tmp/since 的时间戳之后发生更改的文件,而不访问文件夹 'dir1'?
英文:
$ tree -D
.
├── [Jun 25 18:46] dir1
│   └── [Jun 25 18:51] file1
└── [Jun 25 17:59] dir2
└── [Jun 25 18:46] file2
2 directories, 2 files
$ ls -l /tmp/since
-rw-r--r-- 1 xxx None 0 Jun 25 18:45 /tmp/since
It is not clear, why the dir1 folder which is correctly getting excluded
$ find . -name dir1 -prune -o -type f -print
./dir2/file2
in above command, shows up in following command
$ find . -name dir1 -prune -o -type f -newer /tmp/since
./dir1
./dir2/file2
How can I rewrite above find command to list only files that changed
since timestamp of file /tmp/since, without visiting folder 'dir1'?
答案1
得分: 1
以下是您要翻译的内容:
当您执行以下命令时:
$ find . -name dir1 -prune -o -type f -newer /tmp/since
find
隐含地添加了 -print
以使其变为:
$ find . \( -name dir1 -prune -o -type f -newer /tmp/since \) -print
由于 -name dir1 -prune
对于 dir1
为真,因此会执行 -print
,即使 dir1
的子目录不会被处理。
当您明确添加 -print
时,它被解释为:
$ find . \( -name dir1 -prune \) -o \( -type f -newer /tmp/since -print \)
因此,当 -name dir1 -prune
为真时,其余部分被跳过,因此 dir1
不会被打印。
英文:
When you do :
$ find . -name dir1 -prune -o -type f -newer /tmp/since
find
adds implicitly a -print
to make it become
$ find . \( -name dir1 -prune -o -type f -newer /tmp/since \) -print
As -name dir1 -prune
is true for dir1
, -print
is executed, even though the children of dir1
are not processed.
When you add -print
explicitly, it is interpreted as :
$ find . \( -name dir1 -prune \) -o \( -type f -newer /tmp/since -print \)
so when -name dir1 -prune
is true, the rest is bypassed, hence dir1
is not printed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论