Linux
兩個目錄的不同文件
我想比較兩個目錄。我嘗試了 diff 但它包含文件內的更改。我想要的只是這樣的
file a is just in /A file b is missing in /A file c changed directory d is missing in /A directory e is just in /A
我認為這在進行完整文件修補時很常見,但我不知道一個好的解決方案。
您正在尋找
diff -rq (dir1) (dir2)
概念證明:
#!/bin/sh #create our test mkdir -p /tmp/a/b echo "test" >> /tmp/a/c mkdir -p /tmp/a/d/e echo "blah" >> /tmp/a/d/e/f #only exists here mkdir -p /tmp/q/b echo "testing" >> /tmp/q/c #/tmp/a/c shouldnt match mkdir -p /tmp/q/d/e echo "blah" >> /tmp/q/d/e/g #only exists here diff -rq /tmp/a /tmp/q
結果是 :
Files /tmp/a/c and /tmp/q/c differ Only in /tmp/a/d/e: f Only in /tmp/q/d/e: g
您只需要包含**-q**標誌以使其簡短:
# diff -q dir1 dir2 Files dir1/both and dir2/both differ Only in dir1/: one Only in dir2:/ two