Linux compares two files with two commands:
(1)Diff(2)Vimdiff
Cp/etc/grub. conf hello
Add zhangsan at the end of the hello File
Use diff to compare the differences between the two files:
[Root @ rhel ~] # Diff hello/etc/grub. conf
18d17
<Zahnsgan
Vimdiff hello/etc/grub. conf
+ -- 11 lines: grub. conf generated by anac | ++ -- 11 lines: grub. conf generated by ana
Splashimage = (hd0, 1)/grub/splash.xpm.gz | splashimage = (hd0, 1)/grub/splash.xpm.gz
Hiddenmenu | hiddenmenu
Title Red Hat Enterprise Linux (2.6.32-27 | title Red Hat Enterprise Linux (2.6.32-2
Root (hd0, 1) | root (hd0, 1)
Kernel/vmlinuz-2.6.32-279.el6.i6 | kernel/vmlinuz-2.6.32-279.el6. I
Initrd/initramfs-2.6.32-279.el6. | initrd/initramfs-2.6.32-279.el6
Zahnsgan | -------------------------------
When diff is used to compare files, only different rows are displayed. It is not easy to see the differences between files if the files are short.
When you use vimdiff to compare files, open two files in a new window. The differences are displayed in red. It is easy to see the differences between the files. If the files are long, it is difficult to compare them.
DiffThe function of a command is not only as follows. We can also useDiffModify the file patch:
Edit2ItemsFileFile, the difference is only in the last line.
Generate file patches:
Import a file patch to a file:
Note: Command explanation: update the old file into a new file through the patch file, and back up the old file at the same time.
The backup fileOrigEnd.