在bash中查找平面目录中不存在于另一个目录树中的所有文件 [英] in bash find all files in flat directory that don't exist in another directory tree
问题描述
我在目录A
中有很多文件.
I have many files in a directory A
.
其中一些文件存在于具有子目录B/B1
,B/B2
,B/B3
,B/B4
,...的子目录树中
请注意,某些文件的名称中带有空格.
Some of those files exist in a directory tree with sub-directories B/B1
, B/B2
, B/B3
, B/B4
, ...
Note that some files have spaces in their names.
例如:
在目录A
中:
-
有一个名为
A/red file.png
还有另一个名为A/blue file.png
,然后在目录树B
中:
有一个名为B/small/red file.png
在此示例中,我想要一个脚本来告诉我文件blue file.png
在目录B
中不存在.
In this example, I would like a script to tell me that the file blue file.png
does not exist in the directory B
.
如何编写一个脚本,列出在目录树B
下找不到的A
中的所有文件?
How can I write a script that will list all the files in A
that are not found under the directory tree B
?
推荐答案
# A
# ├── blue file.png
# └── red file.png
# B
# └── small
# └── red file.png
$ comm -23 <( find A -type f -printf '%f\n' | sort | uniq ) <( find B -type f -printf '%f\n' | sort | uniq )
blue file.png
如果您的find
缺少-printf
,则可以尝试:
If your find
lacks -printf
, you can try:
comm -23 <( find A -type f -exec basename {} \; | sort | uniq ) <( find B -type f -exec basename {} \; | sort | uniq )
这篇关于在bash中查找平面目录中不存在于另一个目录树中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!