English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux diffstat command

Linux Command大全

The Linux diffstat command displays statistics based on the comparison results of diff.

diffstat reads the output of diff and then counts the differences in insertions, deletions, modifications, and other metrics.

Syntax

diff [-wV][-n <filename length>][-p <filename length>]

Parameter:

  • -Specify the length of the filename, the specified length must be greater than or equal to the longest filename in all files.
  • -p<file name length>  With-The n parameter is the same, but the <file name length> here includes the file path.
  • -w  Specify the width of the output columns.
  • -V  Display version information.

Online Examples

Users can also directly use "|" to pass the output of the diff command to the diffstat command for statistical display.

When using this command, if the file or subdirectory to be compared is not in the current directory, then the complete path should be used.

Use the directory "test1" and "test2" under the same name file "testf.txt" use the diff command for comparison. Then use the diffstat command to display the statistical results, input the following command:

$ diff test1 test2 | diffstat   #Display the statistical results of the comparison

Note: Using this command can very conveniently realize the function of statistical display.

To view the content of a file, users can view it by using the command "cat", as follows:

$ cat test1/testf.txt           #View test1/Content of testf  
abc  
def  
ghi  
jkl  
mno  
pqr  
stu  
vws  
$ cat test2/testf.txt           #View test2/Content of testf  
abc  
def  
ghi  
jkl  
mno

From the above file content display, it can be seen that the differences between the contents of the two files. Now let's run the command just now to display the statistical results of the file comparison, as follows:

testfile | 2 +-             Display of statistical information  
1 file changed, 1 insertion(+) 1 deletion(-)

Linux Command大全