Diff Command
To compare files in Linux Diff command is used. Diff command is available on almost all Linux distributions by default & can be used directly without any packages installation.
Syntax is:
$ diff file1 file2
Vimdiff Command
Vimdiff command is part of vim command, so to be able to use vimdiff we need to have vim installed on our systems. Install vim by using the following command,
CentOS/RHEL/Oracle Linux
$ sudo yum install vim
Ubuntu/Debian/Linux Mint
$ sudo apt-get install vim
Fedora
$ dnf install vim
vimdiff command syntax
$ vimdiff file1 file2
comparing folders use
$ vimdiff folder1 folder2
Lines with no difference appear as it is. For navigating the diffed files, we can use the following keyboard shortcuts,
]c: move to the next difference in the compared files,
[c: go back to the previous difference in the file
dp: put the difference from current window to a new window
do: get the changes from another window to the current window
CTRL-W + CTRL-W: to switch between the split windows
zo: Open the folded content of files
zc: close the folded content
:diffupdate: rescan the files for any changes
That’s it