Easy Tutorial
❮ Linux Comm Fsck Ext2 Linux Comm Ftpwho ❯

Linux diffstat Command

Linux Command Manual

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

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

Syntax

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

Parameters:

Example

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

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

To compare the "testf.txt" files in directories "test1" and "test2" using the diff command and then use the diffstat command to display the statistical results, enter the following command:

$ diff test1 test2 | diffstat   # Perform statistical display of comparison results

Note: This command can be very convenient for statistical display.

To view the contents of a file, users can use the "cat" command, as follows:

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

From the displayed file contents, the differences between the two files can be seen. Now, running the previous command to perform statistical display of the file comparison results yields:

testfile | 2 +-             # Statistical information output display
1 file changed, 1 insertion(+), 1 deletion(-)

Linux Command Manual

❮ Linux Comm Fsck Ext2 Linux Comm Ftpwho ❯