How do I create use the patch command to make sure two file are identical?
hawksbill last edited by
Man page for patch.
We start off with two demo files. fileb is our changed file, we want filea to be the same as fileb.
$ cat filea Shell scripting is foun $ cat fileb Shell scripting is fun
Create a file of differences, using diff.
$ diff -c file[ba] > file.changes
The file.changes file looks like this.
$ cat file.changes *** filea 2020-11-17 11:55:16.364702950 -0800 --- fileb 2020-11-17 11:55:19.688756600 -0800 *************** *** 1 **** ! Shell scripting is foun --- 1 ---- ! Shell scripting is fun
Let's patch filea with the changes of fileb.
$ patch -c filea file.changes patching file filea
$ cat filea Shell scripting is fun
This is an alternative to cut & paste, where many a mistake can be made, extra spaces, blank lines. Of course you can copy and paste and then do you diffs too.
© Lightnetics 2022