Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux diffstat command

Linux diffstat command

Linux Command Reference Linux Command Reference

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

diffstat reads the output of diff and then tallies metrics such as insertions, deletions, and modifications for each file.

Syntax

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

Parameters:

Example

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

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

Use the diff command to compare the file "testf.txt" with the same name in the directories "test1" and "test2". Then use diffstat to display statistics for the result by entering the following command:


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

Note: Using this command makes it very convenient to display statistics.

To view the contents of a file, the user can simply use the "cat" command, 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 shown above, you can see the difference between the two files. Now run the previous command to display statistics for the comparison result, as follows:


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

Linux Command Reference Linux Command Reference