Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

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
[[email protected] huuphan.com]$ cat file1.txt
<####################################>
author: huupv
My Blog: www.huuphan.com
Hello everbody!

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

<####################################>
The default compare line by line with diff comand
[[email protected] 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
[[email protected] 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
[[email protected] huuphan.com]$ diff -u  --color  file1.txt file2.txt

Linux diff command


The output side by side with -y option
[[email protected] 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
[[email protected] 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.


Thanks for reading Linux diff command My blog Zimbra Mail Server,linux,bash script,centos,linux command I hope this is useful.

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com