Wiki‎ > ‎

Difference between 2 directories in linux

posted Jan 9, 2015, 10:38 AM by Dong Xu   [ updated Jul 6, 2016, 8:51 AM ]
diff -r dir1 dir2 | grep dir1 | awk '{print $4}' > difference1.txt

diff -r dir1 dir2 shows which files are only in dir1 and those only in dir2

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

Finally use awk to print only filename.


diff -qr dir1/ dir2/    output "Only"

Should do what you need.

If you also want to see differences for files that may not exist in either directory:

diff -qNr dir1/ dir2/   output "differ"
Comments