Linux for DevOps

“Having a solid understanding of Linux is critical for DevOps practitioners to effectively design, deploy, and manage software systems since DevOps aims to automate the software delivery pipeline. To achieve this goal, DevOps heavily relies on automation tools, cloud platforms, and scalable infrastructure, many of which are built on Linux.”

Today, In this blog, I’m going to talk about :

  1. What is Linux?

  2. Linux file system hierarchy

  3. Basic and useful commands to start off.

Let’s go!

What is Linux?

Linux is an open-source operating system that is based on the Unix operating system. It was developed by Linus Torvalds in 1991 as free and open-source software, and it has since grown to become one of the most widely used operating systems in the world. Linux is known for its stability, security, and flexibility, and it is used in a variety of applications, including servers, desktops, and mobile devices.

One of the main advantages of Linux is its open-source nature, which means that the source code of the operating system is freely available to anyone who wants to use, modify, or distribute it. This has led to the development of a vibrant community of developers who contribute to the development and improvement of the operating system, and it has also led to the creation of a wide range of distributions, or “distros,” that are tailored to specific use cases and user preferences.

Linux Kernel Architecture

Linux is composed of a kernel, which is the core of the operating system, and a set of utilities and libraries that provide additional functionality. The kernel is responsible for managing system resources, such as the CPU, memory, and I/O devices, and it provides a layer of abstraction between the hardware and software components of the system. Utilities and libraries provide a range of tools and functions, such as file management, networking, and security, that enable users to interact with the system and perform various tasks.

Linux File System Hierarchy

File system hierarchy

  1. In Linux everything is represented as a file including a hardware program, the files are stored in a directory, and every directory contains a file with a tree structure. That is called File System Hierarchy.

  2. Linux uses a single-rooted, inverted tree-like structure.

  3. Root Directory represents with / (forward slash). It is a top-level directory in Linux.

  4. The base of the Linux directory is the root. This is the starting point of FSH. Every directory arises from the root directory. It is represented by a forward slash (/).

  5. If someone says to look into the slash directory, they refer to the root directory

Basic and useful Linux commands:

  1. pwd: Command to print the directory location, the current working directory.

2. Sudo: Command to execute actions with a superuser privilege.

3. ls: Command used to list the contents of a directory. If you run “ls -lthr”, it will list the files or directories in the same table format above, but with another column representing the size of each file/directory, sorted by last modified date in descending order (biggest to smallest) and reverse the sorting order.

Note that sizes are listed in bytes (B), megabytes (MB), gigabytes (GB), or terabytes (TB) when the file or directory’s size is larger than 1024 bytes.

4. Cat: The command used to display and concatenate files on the terminal. It can also be used to modify existing ones. Below are other options for the use of the cat

Commands:

cat -b: Adding line numbers to non-blank lines

cat -n: Adding line numbers to all lines

cat -s: Squeezing blank lines into one line

cat -E: Displaying $ at the end of the line

5. grep: Command for searching specific strings/words in a text file.

This would print all of the lines in <file> that contain the word “Dev”.

6. Vim: The most widely used text editor in Linux. Usually used in 3 different modes:

Normal mode: The default mode in which Vim starts. In this mode, you can use various commands to navigate and edit the text

Insert mode: In this mode, you can type text into the file. To enter insert mode, press the “i” key. To exit insert mode and return to normal mode, press the “Esc” key.

Command mode: In this mode, you can enter commands to perform various actions, such as saving the file or quitting Vim. To enter command mode, press the “:” key, and to save press “:wq!”

8. Tail: Command to print the last N number of data of the given input. By default, it prints 10 lines, and even we can specify the number of lines we want to display.

9. Sort: Command used to sort the results of the search either alphabetically or numerically. It also sorts files and directories. There are other options for the use of the sort command:

sort -r: the flag returns the results in reverse order.

sort -f: the flag does case-insensitive sorting.

sort -n: the flag returns the results as per numerical order

10. Ifconfig: Command used to configure the network interfaces.

11. Ps: Command used to list the currently running processes and their PIDs along with some other information depending on different options

There are other options to list the processes:

View process by process ID.
Syntax :

ps p process_id

ps -p process_id

ps — pid process_id

You can view multiple processes by specifying multiple process IDs separated by blank or comma –

12. Sed: Command used to perform basic text transformations on an input file.

13. Diff: Command used to find the difference between two files.

14. Chmod: Command used to change the permissions of files and directories.

15. Chown: Command used to change the file Owner or group

16. History: Command used to verify the previously executed commands.

If you need to check the last 10 executed commands, use the “history 10” command:

17. Free: Command to display the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel.

You can use the “free -mhwl”command to display the amount of memory in megabytes, shows all output columns automatically scaled to the shortest three-digit unit and display the units also of the printout, showing the detailed low and high memory statistics, and the cache memory.

18. Find: Command used to find files and directories.

19. Df: Command used to check the available disk space, used by the file system.

If you use the “df -Th”command, it will show the disk space in a print file system type and in human-readable print sizes in 1024kb.

20. Top: Command used to monitor the system resources and processes.

You can sort processes using different columns, press one of the following keys:

M. Sort by the %MEM column.

N. Sort by PID column.

T. Sort by the TIME+ column.

P. Sort by the %CPU column.

Press Ctrl+C to exit.