File 在bash中,查找平面目录中不包含';不存在于另一个目录树中

File 在bash中,查找平面目录中不包含';不存在于另一个目录树中,file,bash,find,not-exists,directory-tree,File,Bash,Find,Not Exists,Directory Tree,我在目录a中有许多文件 其中一些文件存在于目录树中,其子目录为B/B1,B/B2,B/B3,B/B4。。。 请注意,有些文件的名称中有空格 例如: 在目录A中: 有一个文件名为a/red file.png 还有另一个名为A/blue file.png 并且,在目录树B中: 有一个文件名为B/small/red file.png 在本例中,我想要一个脚本来告诉我文件blue file.png在目录B中不存在 如何编写一个脚本,列出a中在目录树B下找不到的所有文件?这是一个可以处理所有文件

我在目录
a
中有许多文件

其中一些文件存在于目录树中,其子目录为
B/B1
B/B2
B/B3
B/B4
。。。 请注意,有些文件的名称中有空格

例如:

在目录
A
中:

  • 有一个文件名为
    a/red file.png

  • 还有另一个名为
    A/blue file.png

    并且,在目录树
    B
    中:

  • 有一个文件名为
    B/small/red file.png

    在本例中,我想要一个脚本来告诉我文件
    blue file.png
    在目录
    B
    中不存在


如何编写一个脚本,列出
a
中在目录树
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
comm -z23 <(find dir1 -type f -printf '%f\0' | sort -uz) <(find dir2 -type f -printf '%f\0' | sort -uz) | xargs -0 printf '%s\n'

comm-z23谢谢。我的“find”似乎没有-printf,所以我使用了-print。那没什么区别,对吧?等等。有些东西坏了。我仍然在结果中得到A和B中都存在的文件。也许是-printf。当我改用-print时,我会得到整个文件名,包括目录。如果-printf“%f”给了我文件的基名,我会接受答案,但是我如何使这个脚本适应没有-printf的“find”呢?请尝试:
comm-23您使用的是什么操作系统/版本?
comm -z23 <(find dir1 -type f -printf '%f\0' | sort -uz) <(find dir2 -type f -printf '%f\0' | sort -uz) | xargs -0 printf '%s\n'