Linux diff command

In this tutorial, I use diff command output on screen. How to compare different line by line in  files. How to compare side by side, color , output do not output common lines with diff command.

What diff command work?

  • compare files line by line
For example my topic, I compare line by line in 2 file: file1.txt and file2.txt
The content file1.txt file
[huupv@huupv huuphan.com]$ cat file1.txt
<####################################>
author: huupv
My Blog: www.huuphan.com
Hello everbody!

<####################################>
The content file2.txt file
[huupv@huupv huuphan.com]$ cat file2.txt
<####################################>
author: huupv
My Blog: www.devopsrole.com
Hello everbody!

<####################################>
The default compare line by line with diff comand
[huupv@huupv huuphan.com]$ diff file1.txt file2.txt
The output as below:
3c3
< My Blog: www.huuphan.com
---
> My Blog: www.devopsrole.com

The output number lines with -u option
[huupv@huupv huuphan.com]$ diff -u file1.txt file2.txt
The output as below:
--- file1.txt    2018-06-03 10:44:24.215928386 +0700
+++ file2.txt    2018-06-03 10:45:08.740499854 +0700
@@ -1,6 +1,6 @@
 <####################################>
 author: huupv
-My Blog: www.huuphan.com
+My Blog: www.devopsrole.com
 Hello everbody!

 <####################################>

The output with default color
[huupv@huupv huuphan.com]$ diff -u  --color  file1.txt file2.txt

Linux diff command


The output side by side with -y option
[huupv@huupv huuphan.com]$ diff -y file1.txt file2.txt
Linux diff command side by side

The output side by side and do not output common lines with -y , --suppress-common-lines option
[huupv@huupv huuphan.com]$ diff -y --suppress-common-lines file1.txt file2.txt
Linux diff command do not output common lines

Linux diff command with option in this tutorial
  • -y, --side-by-side : output in two columns
  • --suppress-common-lines: do not output common lines

Conclusion 

Thought this article, To help you  compare different line by line in files.


Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server with Country Information

Zimbra Client host rejected Access denied fixed