Ubuntu下删除两个文件夹下相同文件名且相同内容的文件V1.1(分色排版)

前端之家收集整理的这篇文章主要介绍了Ubuntu下删除两个文件夹下相同文件名且相同内容的文件V1.1(分色排版)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Ubuntu下删除两个文件夹下相同文件名且相同内容文件

2017/5/2 17:09

缘起:一直在维护android的BSP,有时候发现另外一个来源的BSP有你所需要的一些功能

因此需要使用一个工具,比对两份代码,将两份BSP里面的相同文件名(内容也完全相同)的文件删除掉。

1、列出两个文件夹dir1、dir2下相同的文件

(英文版本ubuntu)

diff -rs dir1 dir2 | grep 'identical$'

中文版本ubuntu)

rootroot@cm-System-Product-Name:/home/wwt$ diff -rs prk_tina_bak/ fds_tinav2.1/ | grep "相同$" > 3.txt

比较之前预先删除.git和.repo文件

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ rm .repo/ -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ cd ../prk_tina_bak/

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ rm .repo/ -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$

rootroot@cm-System-Product-Name:/home/wwt$ cd prk_tina_bak/

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name .git

./target/.git

./dl/.git

./scripts/.git

./toolchain/.git

./lichee/brandy/.git

./lichee/linux-3.4/.git

./.repo/manifests/.git

./.repo/repo/.git

./tools/.git

./package/.git

./config/.git

./prebuilt/.git

./docs/.git

./build/.git

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name .git | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name .git

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ cd ../fds_tinav2.1/

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name .git

./target/.git

./dl/.git

./scripts/.git

./toolchain/.git

./lichee/brandy/.git

./lichee/linux-3.4/.git

./.repo/manifests/.git

./.repo/repo/.git

./tools/.git

./package/.git

./config/.git

./prebuilt/.git

./docs/.git

./build/.git

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name .git | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name .git

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$

正式使用diff比对,将不同的部分存储到文件:3.txt

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ cd ..

rootroot@cm-System-Product-Name:/home/wwt$ diff -rs prk_tina_bak/ fds_tinav2.1/ | grep "相同$" > 3.txt

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux/lib/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux/lib/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux/lib/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux/lib64/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux/lib64/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux/lib64/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux-musl/lib/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux-musl/lib/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux-musl/lib/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux-musl/lib64/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux-musl/lib64/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/aarch64-openwrt-linux-musl/lib64/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib32/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib32/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib32/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib64/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib64/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/aarch64/toolchain-sunxi/toolchain/lib64/lib64: recursive directory loop

diff: prk_tina_bak/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/arm-openwrt-linux/lib/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/arm-openwrt-linux/lib/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/arm-openwrt-linux-muslgnueabi/lib/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/arm-openwrt-linux-muslgnueabi/lib/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/lib/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/lib/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/lib32/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/lib32/lib: 符号连接的层数过多

diff: prk_tina_bak/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/lib64/lib: 符号连接的层数过多

diff: fds_tinav2.1/prebuilt/gcc/linux-x86/arm/toolchain-sunxi/toolchain/lib64/lib: 符号连接的层数过多

rootroot@cm-System-Product-Name:/home/wwt$

2、删除通过diff比对找到的相同的文件(同名同内容):

awk '{print $2}' 3.txt | xargs rm -rf

awk '{print $4}' 3.txt | xargs rm -rf

参考资料:

http://bbs.csdn.net/topics/320031351

awk如何删除一个文件

awk -F,'{print $2}' test.txt | xargs rm -rf

3、你会发现有很多空的文件/目录,需要把它们找出来删除

由于有些空文件夹里面只有空文件夹,当你删除最底层的空文件夹,上层的文件夹也是空的。

因此需要多次执行!

rootroot@cm-System-Product-Name:/home/wwt$ cd prk_tina_bak/

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ find . -name "*" -type d -empty

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$

rootroot@cm-System-Product-Name:/home/wwt/prk_tina_bak$ cd ../fds_tinav2.1/

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty | xargs rm -rf

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$ find . -name "*" -type d -empty

rootroot@cm-System-Product-Name:/home/wwt/fds_tinav2.1$

参考资料:

http://www.111cn.net/sys/linux/46433.htm

linux中find批量删除文件及空文件夹脚本

查询出所有的空文件

find -type d -empty

http://blog.csdn.net/u010555688/article/details/51280783

Ubuntu 删除两个文件夹下相同文件名的文件

参考:http://bbs.chinaunix.net/forum.PHP?mod=viewthread&tid=1851432&page=1

猜你在找的Ubuntu相关文章