Debian

How to Control File Content in Debian Server

How to Control File Content in Debian Server

Introduction

In this article, we are going to learn how to control file content like a pro in Debian 10 Servers. These commands and instructions are valid for all Linux distributions which have an APT packaging system. I am using Debian 10 Buster Edition to discuss the nature of file manipulation in Linux. Not only everything discussed in this article applies to servers, but also they are helpful for desktop use.

Let’s Begin…!

When it comes to Linux servers, system admins rarely use any graphical user interface. A simple command-line interface also known as CLI is enough for them to get what they are intended to do.

CLI has several advantages, but it also comes with its disadvantages. Beginners with limited knowledge get into trouble and are often seen breaking their servers. This article will walk you through file management, and I believe it will take your skills to next level.

diff & patch

The diff program has the ability to show the difference between two files. I will demonstrate to you how does it do exactly. Once you have experienced the power of diff, you will realize that how powerful your server administration experience will become.

In our case, I have already created two files file1 and file2.

I have also added some content to those files. I will run a very important command to see how different these two files are on my Debian 10 server.

$ diff -u file1 file2

As you can observe, the diff -u command displayed the contents of both files. It also showed when they were updated and at what time.

I have modified file1 for now, and we will run the command again to see a clear picture of file1 on our server.

Let’s run the command again and see the changes.

There you go!

We have added a few more lines and diff program differentiated that the file1 has some markdown comments as well. It also shows when the file1 was modified last time.

Patch Utility

Our next utility is patch. It helps us to take a patch file, the file which was created by diff and applies the difference to a file. Let’s do it now:

$ diff -u file1 file2 > File
$ cat File

You can see that with the help of patch utility, I patched file1 and file2 into File which is now a patch file.

Conclusion

Both diff and patch programs help a Linux server admin to control their files and make new files when things go wrong. A beginner must continue to explore how things work on Linux servers or even on desktops. In case your desktop Linux system does not boot into a graphical user interface then you can use these instructions using the command-line interface. This will help you to take back control of your system and easily solve complex issues.

Similar Posts