在bash中查找平面目录中不存在于另一个目录树中的所有文件 [英] in bash find all files in flat directory that don't exist in another directory tree

查看:103
本文介绍了在bash中查找平面目录中不存在于另一个目录树中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录A中有很多文件.

I have many files in a directory A.

其中一些文件存在于具有子目录B/B1B/B2B/B3B/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆