In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the usage of Linux basic command diff". In daily operation, I believe many people have doubts about the usage of Linux basic command diff. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "the usage of Linux basic command diff"! Next, please follow the editor to study!
Diff
Compare two text files line by line to show the differences in the files to standard output. If you specify that you want to compare directories, the diff command compares files with the same filename in the directory, not subdirectories. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1. Grammar
Diff [options] files
2. List of options
Option
Description
-v |-- version
Display command version information
-- help
Show help documentation
-m |-- mode=MODE
Set the permissions of the directory
-I |-- ignore-case
Ignore case when comparing
-- ignore-file-name-case
Ignore case when comparing file names
-- no-ignore-file-name-case
Case cannot be ignored when comparing file names
-E |-- ignore-tab-expansion
Do not compare tab
-b |-- ingore-space-change
Do not compare the number of spaces
-w |-- ignore-all-space
Ignore all spaces
-B |-- ignore-blank-lines
Do not compare blank lines
-I res |-- ignore-mathcing-lines=res
Lines containing the specified string res are not compared
-- strip-trailing-cr
Go out and enter what follows the line.
-a |-- text
Treat all files as text files
-c-C NUM-- context [= NUM]
Display the front and back parts of the differences. The default is 3 lines.
-u-U NUM-- unified [= NUM]
Displays the front and back parts of the similarities. The default is 3 lines.
-- label LABEL
Use the label of the file instead of the name
-p |-- show-c-function
When comparing c language files, the functions that show the differences
-F RE |-- show-function-line=RE
Show the most recent line that matches the RE
-Q |-- brief
Only show whether there are differences, not details
-e |-- ed
Output an ed script
-- normal
Output a normal diff
-n |-- rcs
The results are displayed in rcs.
-y |-- side-by-side
Display the comparison results in a side-by-side manner
-W num |-- width=NUM
Specify the column width when using the "- y" option
-- left-column
Output only the left column of the common row
-- suppress-common-lines
Do not output public lines
-D NAME |-- ifdef=NAME
Export the merge file to show the difference of'# ifdef NAME'
-- GTYPE-group-format=GFMT
Same as above, the GTYPE input group can be formatted with GFMT
-- line-format=LFMT
Same as above, the GTYPE input group can be formatted with LFMT
-- LTYPE-line-format=LFMT
Same as above, LTYPE input lines can be formatted with LFMT
-l |-- paginate
Pass the output to pr "for paging
-t |-- expand-tabs
Expand tabs to spaces in the output
-T |-- initial-tab
Align tabs with preset tabs
-N |-- new-file
Treat absent files as empty files
-- unidirectional-new-file
Treat the first absent files as empty files
-s |-- report-identical-files
When two files report at the same time
-X FILE |-- exclude-from=FILE
Exclude files that match any pattern in the file
-S FILE |-- starting-file=FILE
When comparing directories from a file
-r |-- recursive
Compare all files in a subdirectory recursively
-x path
Do not compare specified files
-- from-file=FILE1
Compare FILE 1 with all operands. FILE 1 can be a directory
-- to-file=FILE2
Compare all operands to file 2. File 2 can be a directory
-- horizon-lines=NUM
NUM lines that maintain common prefixes and suffixes
-d-- minimal
Try to find a set of smaller changes
-- speed-large-files
Suppose the file is large and there are many scattered small changes.
3. Examples
1) compare two files without parameters (only the first line of the two files is different)
[root@localhost test02] # diff 1.c 2.c / / Direct comparison, only the differences are output here
1c1
Compare two text files line by line to show the differences in the files to standard output.
2) use the option-y to output two files in a separate manner
[root@localhost test02] # diff-y 1.c 2.c / / use option y, where the full contents of the file are displayed as columns
Compare two text files line by line and display the differences in the files to the standard output, adAD file. | compare two text files line by line, and display the differences in the files to standard output.
If you specify to compare directories, the diff command compares texts with the same filename in the directory. If you specify to compare directories, the diff command compares texts with the same filename in the directory.
Scope of application of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUS the scope of application of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUS
[root@localhost test02] # diff 1.c 2.c
3) specify the column width using the option-W
[root@localhost test02] # diff-y-W 100 1.c 2.c / / the column width specified here cannot be fully displayed, so there is no difference.
Compare two text files line by line, display the differences of files to the standard | compare two text files line by line, and display the differences of files to the standard.
If you specify that you want to compare directories, the diff command compares directories. If you specify that you want to compare directories, the diff command compares directories.
Scope of application of this command: RedHat, RHEL, Ubuntu, CentO the scope of application of this command: RedHat, RHEL, Ubuntu, CentO
4) compare catalogs
[root@localhost weijie] # diff test01 test02 / / only compare files with the same name in the directory
Diff test01/1.c test02/1.c
1c1
Compare two text files line by line and display the differences in the files to the standard output, adAD file.
5) use the option-Q to see if it is different
[root@localhost weijie] # diff-Q test01/1.c test02/1.c / / compare whether it is different
Files test01/1.c and test02/1.c differ / / only shows whether it is the same, but does not show the detailed differences.
At this point, the study of "the usage of the Linux basic command diff" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.