Updated: 28 September 2026 · Applies to: GNU diffutils 3.7 to 3.10 and Vim 8.2 to 9.1 on Ubuntu 24.04 and 26.04, Debian 13, AlmaLinux and Rocky Linux 9 and 10

Comparing files is an everyday server task: checking a configuration change, finding what an update altered, or confirming that a backup matches the original. Linux has several tools for this, most of them installed by default.

1. diff: see what changed between two files

diff old.conf new.conf

Lines starting with < are only in the first file, lines with > only in the second. Codes such as 2c2 (line 2 changed) or 3a4 (line added after line 3) say where. For output that is easier to read, use the unified format, with colour:

diff -u --color old.conf new.conf

Here - marks removed lines and + added lines. This is also the format of patch files.

Useful options: -i ignores case, -w ignores all spaces, -B ignores blank lines, -y shows the files side by side.

2. diff -r: compare two directories

diff -rq /etc/nginx /root/nginx-backup

-r goes through subfolders and -q only names the files that differ or exist on one side ("Only in ..."). Leave out -q to see the changed lines too.

3. cmp: are two files identical?

cmp file1.bin file2.bin

cmp works on any file, including binaries, and reports the first byte and line that differ. No output means the files are identical. For large files or files on different servers, comparing checksums is quicker: run sha256sum file on both and compare the result.

4. vimdiff: compare and edit side by side

  1. Install Vim if needed: apt install vim or dnf install vim-enhanced
  2. Open the files: vimdiff old.conf new.conf
  3. Move with ]c (next change) and [c (previous change).
  4. Copy a change with do (take it from the other file) or dp (put it into the other file).
  5. Switch between the two panes with Ctrl+W twice, and save and quit both with :wqa.

vimdiff compares files, not directories. For folders, use diff -r.

5. sdiff and comm

  • sdiff -s old.conf new.conf shows only the differing lines, side by side.
  • comm -3 <(sort list1.txt) <(sort list2.txt) compares two lists, such as user or package lists, and prints the entries found in only one of them.

On a desktop

Meld is a graphical tool for files and folders: apt install meld, or on AlmaLinux and Rocky Linux dnf install meld from the EPEL repository.

Official documentation: GNU diffutils manual.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)