Linux diffstat command
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:
- -n
Specify the file name length; the specified length must be greater than or equal to the longest file name among all files. - -p
Same as the -n parameter, but here the includes the path of the file. - -w Specify the width of the columns in the output.
- -V Display version information.
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