Compare files or directories under Linux __linux

Source: Internet
Author: User
Tags diff

CMP compares two files and indicates whether they are different and different bytes.

Diff compares two files or directories and indicates which files have different rows.

DIFF3 compares three files per line.

Sdiff merges two files and outputs the results interactively.

Vimdiff uses Vim to edit 2 or 3 versions of a document at the same time and displays their differences.

Comm a row for two sorted files, showing the same row in the third column.


Linux diff Sdiff find the difference between a directory and a file: record the usage of my own habits:
Diff-rq/root/launcher/src/com/android/launcher/work/launcher/src/com/android/launcher
This command lists the different file names under two directories (and their subdirectories). The functions of the two parameters are:
-Q: Show no differences only, not show detailed information;
-r: Recursively compares files in subdirectories.


Sdiff-s/work/launcher2/src/com/android/launcher2/workspace.java/root/src/launcher2/workspace.java
Sdiff-l/work/launcher2/src/com/android/launcher2/workspace.java/root/src/launcher2/workspace.java
These two commands are used to compare two files. The functions of the two parameters are:
-L The same row outputs only to the left of the result (the right shows only the contents of the rows that differ from the left);
-S does not display the same row (the contents of the rows with the difference are displayed in two columns).


sdiff Command

Use

Compares two files and displays the differences in a side-by format.

Grammar

Sdiff [-l |-S] [-o outfile] [-w number]file1 File2

Description

The Sdiff command reads the files specified by the File1 and File2 parameters, compares them by using the diff command, and writes the results in side-by-level format to standard output. If the row is the same, the Sdiff command displays each row of two files with a series of spaces. If the row exists only in the file specified by the File1 parameter, the < (less than) is displayed in the blank field, and if the row exists only in the file specified by the File2 parameter, then the > (Greater-than) is displayed and the | (vertical bar) is displayed if the two rows are different.

When you specify the-o flag, the Sdiff command merges the files specified by the File1 and File2 parameters to produce a third file.

Note: The Sdiff command invokes the Diff-b command to compare two input files. The-B flag causes the diff command to ignore trailing spaces and tabs, and to treat other space strings as identical.

Sign

-L

Only the left side is displayed when the row is the same.

-O outfile

Creates the third file specified by the outfile variable by merging the two files specified by the File1 and File2 parameters in a controlled line-by-row basis. The following subcommand manages the creation of the file:

E

Start the ED command with an empty file.

E B or E |

Start ed command from both sides.

E L or E <

Starting from the left of Ed command.

E R or E >

Start on the right ed command.

L

Adds the left to the output file.

R

Adds the right to the output file.

S

Stops displaying the same row.

V

Start showing the same line.

Q

Perform one of the following functions:

· Quit Ed command.

· If the ED command is not running, exit the Sdiff command.

· Exit the two command. This operation is no longer available when the row is merged into the output file.

Each time the ED command is exited, the Sdiff command writes the edited file as the result to the end of the file specified by the outfile variable. If you do not save changes before exiting (for example, by pressing the CTRL-C key order), the Sdiff command writes the initial input to the output file.

-S

The same row is not displayed.

-W Number

Sets the width of the output line. The default value for number variable is 130 characters. The maximum width of the number variable is 2048. The minimum width of the number variable is 20. If the specified value is greater than 2048, then the Sdiff command uses 2048.

example to print a comparison of two files, enter:

Sdiff Chap1.bak Chap1

The Sdiff command displays a side-by-side list that compares each row of Chap1.bak and Chap1 files. To display only a different row, enter:

Sdiff-s-W Chap1.bak chap1

The Sdiff command displays differences on the workstation. -W80 flags and variables set the page width to 80 columns. The-s flag indicates that the same row does not appear in two files. To selectively combine parts of two files, enter:

Sdiff-s-W 80-o chap1.combo Chap1.bak chap1

The Sdiff command combines Chap1.bak and CHAP1 files into a new file known as Chap1.combo. For each set of different rows, the Sdiff command prompts you to keep the group or whether you want to edit it using the ed command. To combine and edit two files (Staff.jan and STAFF.APR) and write the results to the Staff.year file, follow the steps that are marked.

The Staff.jan file contains the following lines:

Member of Accounting department

Andrea

George

Karen

Sam

Thomas

The Staff.apr file contains the following lines:

Member of Accounting department

Andrea

Fred

Mark

Sam

Wendy, please enter the following command:

Sdiff-o Staff.year STAFF.JANSTAFF.APR

The Sdiff command starts comparing the contents of the Staff.jan and staff.apr files and writes the results to the Staff.year file. The Sdiff command displays the following:

Member of Accounting department member of Accounting department

Andrea Andrea

George | Fred

%

% (Percent semicolon) is a command prompt. Enter the e-B subcommand to begin editing the output file using the ed command.

The Sdiff command displays a sequence of numbers that represents the number of bytes of the merged rows. In this case, the number of bytes is 23. Enter the Q subcommand to exit the ED command and continue composing and editing the two files. The Sdiff command displays the following:

D. Sam Sam

E. Thomas | Wendy

Please enter the e-B subcommand again. The ED command must be run whenever a set of rows of two original files is merged into an output file. In this example, the number of bytes is 13. Please enter the Q subcommand to save the changes. When all the rows of two files are merged into the output file, the Q subcommand exits the ED and Sdiff commands.

The Staff.year file now contains the following:

Member of Accounting department

Andrea

George

Karen

Fred

Mark

Sam

Thomas

Wendy

file

/usr/bin/sdiff

Contains the Sdiff command.

Related Article

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.