Q: Why do you want to find a different, why patch?
A:
In Linux applications, as DBAs, we know that MySQL runs on the Linux system, the most important pursuit of database is performance,"stability" is the weight of the heavy, so can not be changed in the system or change it, this time unless it is a last resort, otherwise it is On the original basis to change the line, that is, to the kernel and download some of the source code patching or upgrade , then using diff to make patches under Linux and how to use patch patching is particularly important.
One, find different: diff command (differences)
--Compare files line by line
A line of comparison text file
Role:
compare the differences between the two files, the output is different from two files.
Use the diff command to make patches.
Format:
diff [OPTION] ... FILES
Options:
-U: will put different places together, compact and easy to read
Diff-u test1 test2 > Test.patch (using the diff command to generate patch patches)
-R: Recursively compare all files in directory (when comparing folders, you must answer-R)
1. diff Command: Find different
Shell>CP fruit.txt Shuiguo.txtshell>diff fruit.txt Shuiguo.txt//because it is a copy of the file, so the contents of the file is not different, there is no output resultsShell> Echo"Banana">>fruit.txt Shell>diff fruit.txt Shuiguo.txt 9d8<Banana//after the diff command, the first file has 9 lines, the second file has 8 lines,< indicates that the right file content is missingShell> Echo"Cherry">>shuiguo.txt Shell>diff fruit.txt Shuiguo.txt 9c9<Banana--->Cherry//after the diff command, two files are 9 lines,< right file missing banana,> left file missing Cherry
2. diff command: Make patch file
Shell>Cat Ni.txt Jinanchangqinglinuxchinaitsoftshell>CP ni.txt Wo.txtshell>diff ni.txt Wo.txt Shell> diff-u ni.txt wo.txt //copy File no content differences
Shell> Echo"Zhangjiacai">>wo.txt Shell> diff-u ni.txt wo.txt---ni.txt .- One- Geneva -: One:35.253976996+0800+ + Wo.txt .- One- Geneva -: -:50.037971397+0800@@ -2,3+2,4@@ changqing Linux chinaitsoft+Zhangjiacaishell>Vim ni.txt Shell>Cat Ni.txt Jinanlinuxchinaitsoftshell> diff-u ni.txt wo.txt---ni.txt .- One- Geneva -: -:32.930978061+0800+ + Wo.txt .- One- Geneva -: -:50.037971397+0800@@ -1,3+1,5@@ Jinan+changqing Linux Chinaitsoft+zhangjiacai
Analytical:
@@ 代表 a certain range
-Representative Ni.txt
+ Represents Wo.txt
Use > Output redirect Generate patch file Ni-to-wo.patch
shell> diff-u ni.txt wo.txt > ni-to-Wo.patchshell> Cat ni-to-Wo.patch---ni.txt .- One- Geneva -: -:32.930978061+0800+ + Wo.txt .- One- Geneva -: -:50.037971397+0800@@ -1,3+1,5@@ Jinan+changqing Linux Chinaitsoft+zhangjiacai
So, we have a patch file ready.
Second, patching: Patch command
---apply a diff file to an original.
Use:
Patch files for patching---
Format:
patch [Options] Raw files < patch files
-pn:n means ignoring n-tier paths
-R: Revert to old version
Precautions:
① if hit multiple patches, pay attention to order;
② do not modify the source files before patching;
1. Comparison of documents and documents
Shell>diff ni.txt Wo.txt 1a2>Changqing3a5>Zhangjiacaishell> diff ni.txt Wo.txt >ni-to-wo.patch//Generate patch filesShell> Patch Ni.txt <ni-to-wo.patch//hit PatchPatching file Ni.txtshell> diff Ni.txt Wo.txt//hit Patch SuccessShell> Patch-r ni.txt <ni-to-wo.patch//revert to the original version (undo patching)Patching file Ni.txtshell>diff ni.txt Wo.txt 1a2>Changqing3a5> Zhangjiacai
2. Comparison of directories and directories
[email protected] test]# tree qq-v1qq-v1├──hosts└──image└──1. Txt[[email protected] test]# tree QQ-V2QQ-v2├──hosts├──image│└──1. txt├──passwd└──sound└──3. Txt[[email protected] test]# diff-ur Qq-v1 qq-v2 onlyinchqq-v2:passwdonlyinchQq-v2/sound:3. Txt[[email protected] test]# diff-nur Qq-v1 qq-v2 diff-nru qq-v1/passwd qq-v2/passwd---qq-v1/passwd1970- on- on ,:xx:00.000000000+0800+ + QQ-V2/PASSWD .- One- Geneva -: -:47.664980339+0800@@ -0,0+1, to @@+ROOT:X:0:0: root:/root:/bin/Bash+BIN:X:1:1: Bin:/bin:/sbin/nologin
Analytical:
-N--new-file (Treat absent files as empty) If there is no file, take an empty file and compare it to the files in the other directory.
Make patch files to patch the directory
[[email protected] test]# Diff-nur qq-v1 qq-v2 >patch-v2.txt # compare folders generate patch files --Alternate: patch file Patch-v2.txt in the test directory
-pnum or--strip=num
Strip the smallest prefix containing num leading slashes from each file name
Found in the patch file.
For example: /a/b/c/d/e/f/g
the effect of-P3 is to remove the 3rd/previous content, the effect: c/d/e/f/g
the effect of-P4 is to remove the 4th/previous content, the effect: d/e/f/g
1> Inner Layer Patching
[[ Email protected] test]# CD qq-v1 #进入qq目录, go inside to patch [[email protected] qq-v1]# patch-P1 < /patch-v2.txt Patching file passwdpatching file sound/3. Txt[[email protected] qq-v1]# CD.. [[Email protected] test]# diff-nru Qq-v1 qq-v2 //No output indicated patch success [[email protected] test]# CD Qq-v1[[email protected] qq-v1]# patch-R-P1 < /patch-v2.txt//Undo PatchPatching file passwdpatching file sound/3. Txt[[email protected] qq-v1]# CD.. [[Email protected] test]# diff-nru Qq-v1 qq-V2diff-nru qq-v1/passwd qq-v2/passwd---qq-v1/passwd1970- on- on ,:xx:00.000000000+0800+ + QQ-V2/PASSWD .- One- Geneva -: -:47.664980339+0800@@ -0,0+1, to @@+ROOT:X:0:0: root:/root:/bin/Bash+BIN:X:1:1: Bin:/bin:/sbin/nologin
2> Outer patch
// if Qq-v1 and Qq-v2 are in the same directory, you do not need to remove a layer of paths -p0 <patch-patching file qq-v1/passwdpatching file qq-v1/sound/3. Txt
Wall Crack Recommendations:
Before any action, remember to make a backup of the files and directories to prevent the failure of the operation resulting in data loss.
Look different under Linux-patching