Use of diff and vimdif in Linux shell programming RHEL6

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.