patch and diff


The diff command is used to compare two files or directories and produce the differences between them in a unified or context format.

The patch command is used to apply a patch file to a target file or directory. A patch file contains the differences generated by the diff command.


# simple comparison of 2 files
diff file1.txt file2.txt > file_diff.patch

# apply patch for one file
patch file1.txt < file_diff.patch

# generate patch file for directory
diff -ruN ./dir/subdir1/ ./dir/subdir2/ > dir_diff.patch

# apply patch for dir
patch -s -p0 < dir_diff.patch