0
0
Linux CLIscripting~15 mins

diff for file comparison in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Compare Two Text Files Using diff
📖 Scenario: You work as a system administrator. You often need to check if two configuration files are the same or if they have differences.Using the diff command helps you quickly find differences between two files.
🎯 Goal: Learn how to use the diff command to compare two text files and see their differences.
📋 What You'll Learn
Create two text files with specific content
Use the diff command to compare the two files
Understand the output of diff showing differences
💡 Why This Matters
🌍 Real World
System administrators and developers often need to check differences between configuration files or code versions to troubleshoot or review changes.
💼 Career
Knowing how to use diff is essential for tasks like code reviews, debugging, and managing system configurations.
Progress0 / 4 steps
1
Create the first file file1.txt
Create a file called file1.txt with these exact three lines:
apple
banana
cherry
Linux CLI
Need a hint?

Use echo with -e to add new lines and redirect output to file1.txt.

2
Create the second file file2.txt
Create a file called file2.txt with these exact three lines:
apple
banana
date
Linux CLI
Need a hint?

Use echo with -e and redirect output to file2.txt.

3
Use diff to compare the two files
Use the diff command with file1.txt and file2.txt to find differences between them.
Linux CLI
Need a hint?

Simply run diff file1.txt file2.txt to see the differences.

4
View the output showing the difference
Run the script and observe the output. It should show the difference between file1.txt and file2.txt indicating that cherry was replaced by date.
Linux CLI
Need a hint?

The output shows line 3 changed from cherry to date.