bash-tutorial/tutorial/diff.org

1.0 KiB

Comparing the content of two files or directories

diff is a command line utility used to compare two files or directories

Compare files

To compare the content of two files use something like

  diff file1.txt file2.txt

You can redirect the output to a file and make a patch: a file containing the differences between both files

  diff file1.txt file2.txt  > patch.txt

Comparing directories

Some arguments may be hepful to have an output showing the differences between two directories:

  • --brief (show only the differences) and
  • -r (compare the directories that are located within the main directory also)
  diff --brief -r directory1 directory2

Another approach to compare all the files within each directory is to use:

  • q : Shows only differences
  • r : Run the command recursively
  diff -qr directory1 directory2