在Linux中2个目录的区别 [英] difference between 2 directories in linux

查看:84
本文介绍了在Linux中2个目录的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出存在于一个目录,但不是在其他文件,我试图用这个命令:

 差异-q DIR1 DIR2

与上面的命令找到这两个文件中的 DIR1 ,但不是在 DIR2 以及问题在文件 DIR2 ,但不是在 DIR1

我试图找到 DIR1 中的文件,但不是在 DIR2

下面是一个什么样我的数据看起来像

一个小样本

  DIR1 DIR2 DIR3
1.TXT 1.TXT 1.TXT
2.txt 3.txt 3.txt
5.txt 4.txt 5.txt
6.txt 7.txt 8.txt

在我脑海里的另一个问题是我怎么可以在 DIR1 DIR2 的文件,但没有或 DIR3 在一个命令?


解决方案

 差异-r DIR1 DIR2 | grep的DIR1 | AWK'{打印$ 4}'> difference1.txt

说明:


  • 差异-r DIR1 DIR2 显示哪些文件只在DIR1而那些只在DIR2,也是在这两个目录中的文件present的变化(如有)。


  • 差异-r DIR1 DIR2 | grep的方向1 显示哪些文件只在DIR1


  • AWK 只打印文件名。


I'm trying to find the files existing in one directory but not in the other, I tried to use this command:

diff -q dir1 dir2

The problem with the above command that it finds both the files in dir1 but not in dir2 as well as the files in dir2 but not in dir1,

I am trying to find the files in dir1 but not in dir2 only.

Here's a small sample of what my data looks like

dir1    dir2    dir3
1.txt   1.txt   1.txt
2.txt   3.txt   3.txt
5.txt   4.txt   5.txt
6.txt   7.txt   8.txt

Another question on my mind is how can I find the files in dir1 but not in dir2 or dir3 in a single command?

解决方案

diff -r dir1 dir2 | grep dir1 | awk '{print $4}' > difference1.txt

Explanation:

  • diff -r dir1 dir2 shows which files are only in dir1 and those only in dir2 and also the changes of the files present in both directories if any.

  • diff -r dir1 dir2 | grep dir1 shows which files are only in dir1

  • awk to print only filename.

这篇关于在Linux中2个目录的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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