在bash中查找平面目录中另一个目录树中不存在的所有文件

mar*_*bik 3 bash file 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

The*_*ard 6

# 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
Run Code Online (Sandbox Code Playgroud)

如果你find缺乏-printf,你可以尝试:

comm -23 <( find A -type f -exec basename {} \; | sort | uniq ) <( find B -type f -exec basename {} \; | sort | uniq )
Run Code Online (Sandbox Code Playgroud)