Forrest logo
tool overview
On this page you find all important commands for the CLI tool diff. If the command you are looking for is missing please ask our AI.

diff

The 'diff' command line tool is used to compare the contents of two files or directories and display the differences between them. It shows which lines or files are added, modified, or removed.

Here are some key aspects of the 'diff' command:

  1. Syntax: The basic syntax of 'diff' is as follows: 'diff [options] file1 file2'. It takes two file arguments as input and compares them.

  2. Output: The output of 'diff' shows the differences between the two files with specific markings. Lines starting with '<' indicate lines present only in file1, while lines starting with '>' denote lines present only in file2. Lines starting with '---' and '+++' signify the context or file name. Lines starting with '!' represent differences within changed lines.

  3. Directories: 'diff' can also be used to compare directories. In this case, the tool compares the files within the directories and highlights any differences it finds.

  4. Options: 'diff' provides various options to customize the output and behavior. Some commonly used options include '-c' (context output), '-u' (unified output), '-r' (recursive comparison of directories), and '-q' (brief output indicating only whether files differ or not).

  5. Patching: 'diff' output can be used to create "patches". By redirecting the output to a file using the '>' operator, the differences can be saved as a patch file. The patch file can then be applied to another version of the file using 'patch' command.

Overall, the 'diff' command line tool is an essential utility for comparing files and directories, enabling users to identify and understand the differences between versions.

List of commands for diff:

  • diff:tldr:1a22d diff: 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}
    try on your machine
    explain this command
  • diff:tldr:2464e diff: Compare directories recursively (shows names for differing files/directories as well as changes made to files).
    $ diff --recursive ${old_directory} ${new_directory}
    try on your machine
    explain this command
  • diff:tldr:2d9aa diff: Compare files (lists changes to turn `old_file` into `new_file`).
    $ diff ${old_file} ${new_file}
    try on your machine
    explain this command
  • diff:tldr:553fa diff: Compare files, showing the differences in unified format (as used by `git diff`).
    $ diff --unified ${old_file} ${new_file}
    try on your machine
    explain this command
  • diff:tldr:bd06d diff: Compare files, ignoring white spaces.
    $ diff --ignore-all-space ${old_file} ${new_file}
    try on your machine
    explain this command
  • diff:tldr:de649 diff: Compare directories, only showing the names of files that differ.
    $ diff --recursive --brief ${old_directory} ${new_directory}
    try on your machine
    explain this command
  • diff:tldr:ec137 diff: Compare files, showing the differences side by side.
    $ diff --side-by-side ${old_file} ${new_file}
    try on your machine
    explain this command
  • diffstat:tldr:9bddb diffstat: Display inserted, deleted and modified changes as a table.
    $ diff ${file1} ${file2} | diffstat -t
    try on your machine
    explain this command
  • diffstat:tldr:c495d diffstat: Display changes in a histogram.
    $ diff ${file1} ${file2} | diffstat
    try on your machine
    explain this command
  • sops:tldr:21bc0 sops: Show the difference between two sops files.
    $ diff <(sops -d ${path-to-secret1-enc-yaml}) <(sops -d ${path-to-secret2-enc-yaml})
    try on your machine
    explain this command
tool overview