# Create patch file ###### tags: `linux`, `patch` Basic example to use "patch" command. #### create a patch file ``` diff -Naur <absolute path of old file > <absolute path of new file> ``` ``` # create a reverse patch file (just swap new and old file) diff -Naur <absolute path of new file> <absolute path of old file> ``` #### apply a patch file ``` patch -r- -p0 -d / -N -i <absolute path of patch file> # create a backup patch -b -r- -p0 -d / -N -i <absolute path of patch file> ``` #### reverse a patched file ``` patch -R <absolute path of patched file> <absolute path of patch file> ``` Or, use "reverse patch file" to patch. #### reverse patched file by move backup file (.orig) to the patched file name ``` for i in *.orig; do base=`basename ${i} .orig` mv $i $base done ``` #### Reference - https://www.gnu.org/software/diffutils/manual/html_node/Reversed-Patches.html - https://www.manpagez.com/info/diff/diff_83.php