• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Day 21/ 30 Days of Linux Mastery: 'diff' Command

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
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 OptionsDescription
-yDisplays output side by side
-cProduces a context diff (shows surrounding lines)
-uUnified diff format (commonly used for patches)
--colorAdds color to differences in output
-rRecursively compares directories
--suppress-common-linesUsed 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

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

.
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


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу