• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

diff: command not found

by admin

The diff command is used to compare text files. The command displays the two files and the differences between them. Using various symbols, the output suggests how you can change one file to make it identical to the other. Each symbol has a special meaning.

The less than symbol (<) with a line after it means that line should be removed from the first file because it doesn't appear in the second. The greater than symbol (>) with a line after it means that line should be added from the second file. In addition, the diff command also denotes the line numbers for each file that would be affected by deletion, addition, and change operations.

Syntax

The syntax of the diff command is:

# diff {file name 1} {file name 2}

diff COMMAND OPTIONS

The diff command has various options that enable you to specify the nature of the output.

Option Description
-b Ignore spacing differences.
-i Ignore case differences.
-t Expand tab characters in output lines.
-w Ignore spacing differences and tabs.
-c Display a list of differences with three lines of context.
-u Output results in unified mode, which presents a more streamlined format.

If you encounter the below error while running the diff command:

diff: command not found

you may try installing the below package as per your choice of distribution:

OS Distribution Command
OS X brew install diffutils
Debian apt-get install diffutils
Ubuntu apt-get install diffutils
Alpine apk add diffutils
Arch Linux pacman -S diffutils
Kali Linux apt-get install diffutils
CentOS yum install diffutils
Fedora dnf install diffutils
Raspbian apt-get install diffutils

diff Command Examples

1. Compare files (lists changes to turn `old_file` into `new_file`):

# diff old_file new_file

2. Compare files, ignoring white spaces:

# diff --ignore-all-space old_file new_file

3. Compare files, showing the differences side by side:

# diff --side-by-side old_file new_file

4. Compare files, showing the differences in unified format (as used by `git diff`):

# diff --unified old_file new_file

5. Compare directories recursively (shows names for differing files/directories as well as changes made to files):

# diff --recursive old_directory new_directory

6. Compare directories, only showing the names of files that differ:

# diff --recursive --brief old_directory new_directory

7. Create a patch file for Git from the differences of two text files, treating nonexistent files as empty:

# diff --text --unified --new-file old_file new_file > diff.patch

8. diff can also compare directories:

# diff dir1 dir2

which compares any same-named files in those directories, and lists all files that appear in one directory but not the other. To compare entire directory hierarchies recursively, use the -r option:

# diff -r dir1 dir2

which produces a (potentially massive) report of all differences.

Conclusion

The diff command compares two files line-by-line, or two directories. When comparing text files, diff can produce detailed reports of their differences. For binary files, diff merely reports whether they differ or not. For all files, if there are no differences, diff produces no output.

Filed Under: Linux

Some more articles you might also be interested in …

  1. debootstrap: command not found
  2. ledctl Command Examples in Linux
  3. Grsync: Graphical rsync backup tool in Ubuntu Linux
  4. dmidecode Command Examples in Linux
  5. ip: command not found
  6. mkfs.fat: command not found
  7. Understanding dm-Multipath Identifiers in Linux
  8. playerctl Command Examples in Linux
  9. hashcat: command not found
  10. e2undo Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright