Linux diffstat Command

Linux 命令大全Linux Command Reference

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

diffstat reads the output of diff, then counts the insertions, deletions, modifications and other difference metrics for each file.

Syntax

diff [-wV][-n <文件名长度>][-p <文件名长度>]

Parameters:

  • -n<filename length> Specify the filename length. The specified length must be greater than or equal to the longest filename among all files.
  • -p<filename length> Same as the -n parameter, but the <filename length> here includes the file path.
  • -w Specify the width of the fields during output.
  • -V Display version information.

Examples

Users can also directly use "|" to pipe the output of the diff command to the diffstat command for displaying the statistical results.

When using this command, if the files or subdirectories being compared are not in the current directory, their full paths should be used.

Compare the same-named file "testf.txt" under directories "test1" and "test2" using the diff command. Then use the diffstat command to statistically display the results. Enter the following command:

$ diff test1 test2 | diffstat   #进行比较结果的统计显示

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

To view the contents of the files, users can use the "cat" command. The specific operations are as follows:

$ cat test1/testf.txt           #查看test1/testf的内容  
abc  
def  
ghi  
jkl  
mno  
pqr  
stu  
vws  
$ cat test2/testf.txt           #查看test2/testf的内容  
abc  
def  
ghi  
jkl  
mno

From the file contents displayed above, you can see the differences between the two files. Now run the command just mentioned to statistically display the file comparison results. The results are as follows:

testfile | 2 +-             #统计信息输出显示  
1 file changed, 1 insertion(+), 1 deletion(-)

Linux 命令大全Linux Command Reference

Other Extensions