Short post so that I can remember this everytime I need to do something similar!
Using diff
on more than individual files
#
The quick and dirty explaination is that the GNU/Linux diff
command has an -r
flag to recursively compare two folders. The command help indicates that it is shorthand for the full --recursive
flag, which might be easier to remember.
1
2
3
4
5
|
diff --help
# ...
-r, --recursive recursively compare any subdirectories found
# ...
|
Example
#
In the following example, “Only in” shows that particular files are only found in one of the folders. By default, matching files are not shown. If a file can be found in both folders and the two versions differ, the normal diff
output is provided along with the modified times. All together these details provide a good summary of what a user might want to know when comparing two directories.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
diff -bur /your/folder/swarm-aws/ /another-folder/swarm/
# Only in /your/folder/swarm-aws/: AWS Forecat Feed Production.md
# Only in /your/folder/swarm-aws/: AWS Forecat Feed Production.pdf
# Only in /another-folder/swarm/: contains_string.py
# Only in /your/folder/swarm-aws/: ec2-user-data-script-swarm.sh
# Only in /your/folder/swarm-aws/: .git
# Only in /your/folder/swarm-aws/: hosts
# diff -bur /your/folder/swarm-aws/init.sh /another-folder/swarm/init.sh
# --- /your/folder/swarm-aws/init.sh 2022-12-14 10:38:15.705039678 -0500
# +++ /another-folder/swarm/init.sh 2022-08-09 15:24:11.000000000 -0400
# @@ -4,4 +4,4 @@
#
# {some other things in both files, from the -u unified context}
#
# -grep image /another-folder/swarm/*y*ml | awk '{print $3}' | sort | uniq | parallel docker pull {}
# +grep "image:" /another-folder/swarm/*y*ml | awk '{print $3}' | sort | uniq | parallel docker pull {}
# Only in /another-folder/swarm/: log.txt
# Only in /your/folder/swarm-aws/: no_git_track
# Only in /your/folder/swarm-aws/: scp_to.sh
|
The -b
flag ignores differences that only involve whitespace.