DEV Community

Cover image for Unveil the Secrets of Ancient Scrolls with Linux File Diff
Labby for LabEx

Posted on

Unveil the Secrets of Ancient Scrolls with Linux File Diff

Introduction

In the lost era of ancient Atlantis, a thriving civilization once held knowledge far beyond our current comprehension. Among the Atlanteans, there was a renowned treasure hunter known only as Lykos. Lykos possessed a unique artifact that could compare the contents of ancient scrolls with uncanny precision, revealing differences that would lead to the discovery of untold riches and secrets.

In this lab, as modern-day treasure hunters and guardians of the Atlantean legacy, our objective is to master the technique of comparing digital ancient scrolls - or in our terms, files - using the vimdiff tool in Linux. This powerful skill will not only unveil differences in code that could shape the future of our projects but also bring us a step closer to the wisdom of the ancients.

Preparing the Scrolls

In this step, you will create two 'ancient scrolls' or files that we will later compare using vimdiff. By preparing these files, you shall set the foundation of our quest for knowledge and digital treasure.

First create the project directory and navigate to it:

mkdir -p ~/project
cd ~/project
Enter fullscreen mode Exit fullscreen mode

Next, create two sample text files named scroll_one.txt and scroll_two.txt:

echo "The quick brown fox jumps over the lazy dog" > scroll_one.txt
echo "The quick brown lynx jumps over the lazy dog" > scroll_two.txt
Enter fullscreen mode Exit fullscreen mode

Review the contents of each scroll:

cat scroll_one.txt
cat scroll_two.txt
Enter fullscreen mode Exit fullscreen mode

The expected output should be the text we echoed into the files. Notice how in scroll_two.txt, the word 'lynx' is used instead of 'fox'.

Unveiling the Differences

Once the scrolls are ready, it's time to reveal their secrets. In this step, you will use the vimdiff command to visually compare the differences between the two scrolls.

Execute the following command to start your comparison:

vimdiff scroll_one.txt scroll_two.txt
Enter fullscreen mode Exit fullscreen mode

Inside vimdiff, you will see the two files side by side, with the differences highlighted. To navigate between the differences, you can use ]c to go to the next difference and [c to go to the previous difference.

To exit vimdiff, type :qall and press Enter.

Observe the differences and take note of how vimdiff highlights them.

Summary

In this lab, we embarked on a digital treasure hunt reminiscent of ancient Atlantean wisdom, learning the essential skills of comparing files in a Linux environment via vimdiff. The steps designed took you through the creation of files, the practical application of vimdiff, and the navigation within its interface.

Through this hands-on experience, you have gained a valuable skill that will assist in code review, configuration management, and understanding the nuances of file changes. May the precision of the Atlantean technology guide you in your future coding adventures.


🚀 Practice Now: Linux File Difference Viewing


Want to Learn More?

Top comments (0)