Table of Contents
- Introduction
- What is the
diff
Command? - Core
diff
Commands - Real-World Scenario:
diff
Command - Conclusion
- Let's Connect
Introduction
Welcome back to Day 21 of this practical Linux challenge! Today, we are diving into one of the most useful Linux commands: diff
.
Knowing how to compare files is a core skill that shows attention to detail and debugging awareness.
What is the diff
Command?
The diff
command helps you compare the contents of two files line by line. It’s essential for:
- Verifying configuration changes
- Reviewing file versions
- Debugging or troubleshooting mismatches
- Pre-deployment audits
This is especially useful in production environments where systems grow large and messy fast.
Core diff
Commands
Basic Syntax for diff
is
diff [options] file1 file2
More commonly used diff commands options are listed in the table below.
diff Options |
Description |
---|---|
-y |
Displays output side by side |
-c |
Produces a context diff (shows surrounding lines) |
-u |
Unified diff format (commonly used for patches) |
--color |
Adds color to differences in output |
-r |
Recursively compares directories |
--suppress-common-lines |
Used with -y , hides lines that are the same |
Real-World Scenario: diff
Command
- We will create a file, then copy it as a backup and modify it by adding more words inside.
- Compare the files using
diff
diff demologs.txt demologsbackup.txt
- Let's use side-by-side comparison to view the files easily
diff -y demologs.txt demologsbackup.txt
you can see the last line that was included.
- Use Unified Format for Patching
diff -u demologs.txt demologsbackup.txt > patch.diff
This creates a .diff file that can be used to patch another demolog file using patch. Shows you the modification and versions of both files.
Conclusion
Whenever you need to check a file and compare with older versions to see changes or modifications, always think of using the diff
command!
The diff
command is not flashy, but it is one of those must-know tools that gets real work done. Whether you are reviewing configs, debugging a deployment, or managing drift in production, diff
helps you stay in control.
If this is helpful to you, feel free to bookmark, comment, like and follow me for Day 22!
Let's Connect!
If you want to connect or share your journey, feel free to reach out on LinkedIn.
I am always happy to learn and build with others in the tech space.
#30DaysLinuxChallenge #Redhat#RHCSA #RHCE #CloudWhistler #Linux #Rhel #Ansible #Vim #CloudComputing #DevOps #LinuxAutomation #IaC #SysAdmin#CloudEngineer
Top comments (0)