in bash find all files in flat directory that don't exist in another directory tree

老子叫甜甜 提交于 2019-12-05 23:21:04
# 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

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 )

This is version which can cope with all filenames, including ones containing newlines:

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'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!