# Linux Essentials

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690541650757/8a116009-7de8-4edd-8317-2036293f2b53.png align="left")

### **TABLE OF CONTENTS**

* [**Introduction:**](https://vedkulkarni.hashnode.dev/day-2-linux-fundamentals#heading-introduction)
    
* [**What is Linux?**](https://vedkulkarni.hashnode.dev/day-2-linux-fundamentals#heading-what-is-linux)
    
* [**Components of the Linux File System:**](https://vedkulkarni.hashnode.dev/day-2-linux-fundamentals#heading-components-of-the-linux-file-system)
    
* [**The architecture of Linux:**](https://vedkulkarni.hashnode.dev/day-2-linux-fundamentals#heading-architecture-of-linux)
    
* [**Basic Linux Commands:**](https://vedkulkarni.hashnode.dev/day-2-linux-fundamentals#heading-basic-linux-commands)
    
    ## Introduction:
    

Today, we will dive into the fundamental concepts of Linux, an open-source operating system that plays a crucial role in the world of DevOps. Understanding Linux is essential for any DevOps practitioner, as it forms the foundation of many server environments and provides a powerful platform for running applications and managing resources. In this blog post, we will explore the key components of Linux, its architecture, and some basic commands to get you started on your Linux journey

## What is Linux?

Linux is an open-source operating system that serves as the foundation for numerous computing systems. Linux allows users to access and modify its source code. Linux interacts directly with a system's hardware, managing resources such as the CPU, memory, and storage. It provides a robust and secure platform for running applications and servers.

## Components of the Linux File System:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690540095131/615cad66-d2dc-45d0-8db2-ce28ed321408.png align="center")

**a. Kernel:** The Linux kernel is the core part of the operating system. It interacts directly with the hardware, providing an abstraction layer that hides low-level hardware details from system and application programs. It handles key activities and manages resources efficiently.

**b.** **System Libraries:** Linux offers a set of system libraries that implement most of the functionalities of the operating system. These libraries provide functions and programs that allow application programs and system utilities to access the kernel's features without requiring direct access rights to the kernel modules.

**c.** **System Utility Programs**: System utility programs in Linux perform specialized and individual tasks. These programs help manage the system, configure settings, perform administrative functions, and automate various operations.

## The architecture of Linux:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689503869945/dfd98af0-2b08-4b9f-b7ab-843154e3115a.png?auto=compress,format&format=webp align="left")

**A Linux system consists of several layers:**

**a. Kernel:** The kernel is the heart of the Linux operating system. It handles critical tasks, manages hardware resources, and provides an interface for system processes and applications.

**b. System Libraries:** These libraries contain pre-compiled functions and code that allow applications to interact with the kernel and access system resources. They provide an abstraction layer, simplifying the development process for software developers.

**c. System Utility Programs:** System utility programs offer a range of functionalities to manage and configure the system. Examples include package managers, network configuration tools, and system monitoring utilities.

**d. Hardware Layer:** This layer comprises the physical components of the system, including the CPU, hard disk drives (HDD), RAM, and other peripheral devices.

**e. Shell:** The shell acts as an interface between the user and the kernel. It can be either a command-line shell or a graphical shell, enabling users to interact with the system and execute commands.

## Basic Linux Commands:

To get started with Linux, here are some essential commands:

a. ls : Lists files and directories in the current location : `ls`

b. cd: Changes the current directory:`cd directory_name`

c. mkdir: Creates a new directory : `mkdir directory_name`

d. touch: creates a new file: `touch file_name`

e. rm: Removes a file : `rmdir directory_name`

f. cp: Copies a file : `cp source_file destination path`

g. mv: Moves or renames a file : `mv source_file destinamtion`

h. cat : Displays the contents of a file : `cat file_name`

i. Clear: Clears the terminal screen : `clear`

j.history: Shows a list of previously executed commands : `history`

### **Some performed operations :**

**Present Working Directory (pwd)**

The Print/Present Working Directory command (pwd) allows you to quickly check your current location in the file system. It provides the absolute path of the directory you are currently working in.

Command: pwd: /home/user

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690540938575/584d5ca8-22f4-473d-8ed5-21149a0f80a4.png align="left")

**Long List (ls -a)**

The Long List command (ls) with the option -a is a versatile tool for listing directories and files, including hidden ones. It provides detailed information about each item, such as permissions, ownership, size, and last modification date.

Command -1 : ls: (Displays the list of directories and files in the current directory)

Command -2 : ls -a : (Displays the list of directories and files, including hidden ones)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690540891275/b85d93b2-5022-4f97-bec7-65a2ff69f2ea.png align="left")

**Create a Nested Parent Directory**

Creating nested directories can be accomplished easily using the mkdir command with the -p flag. This allows you to create multiple directories simultaneously, even if the parent directories don't exist.

Command: mkdir -p test1/test2/test3 Output: (Creates the nested directories test1/test2/test3)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690541189586/b4d3b74a-6e36-49d3-87fa-987d6c6373f7.png align="left")

### **1: View the Contents of a File**

To view the contents of a file, we can use the `cat` command. For example, if we have a file named `test.txt`, we can enter the following command in the terminal:

cat test.txt, this will display the contents of the file on the terminal screen.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690544780023/a743f7f7-1105-409c-969f-dcfb26a541c4.png align="left")

### **2: Change File Access Permissions**

To change the permissions of files or directories, we use the `chmod` command, which stands for "change mode." In Linux, every file has three types of permissions: read (r), write (w), and execute (x). These permissions can be set for three different categories of users: the file's owner (u), the group (g) the file belongs to, and others (o) who are not the owner or part of the group.

For example, let's assume we have a file named `test.txt` where the user has read and execute access, and the group has read, write, and execute access. If we want to give the user read, write, and execute access, and the group only read access, we can use the following command:

In the above command, `u+rwx` grants read, write, and execute permissions to the file owner, and `g-wx` revokes write and execute permissions from the group.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690544994629/79851d72-200b-42dc-83f9-4cc681ac876f.png align="left")

### **3: Check Command History**

To check the commands you have run in the current terminal session, you can use the `history` command. This command displays a list of previously executed commands, along with their line numbers.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690545041209/c4c1a74c-3460-41f0-a104-d85d6c4f4ae0.png align="center")

### **4: Remove a Directory/Folder**

To remove a directory or folder, we can use the `rmdir` or `rm` command. The `rmdir` command is used specifically to remove empty directories, while the `rm` command can be used to remove directories with contents and files.

For example, to remove an empty directory named `XYZ`:

And to remove a directory with contents and files named `XYZ`:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690545072964/aefc8e05-2d77-4a94-85c2-5535f23b3142.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690545174556/0011e1c4-cf57-4f8c-a12d-31fe130841d2.png align="left")

### **5: Create and View the Content of a File**

To create a file, we can use the `touch` command to create a file named `devopstools.txt`:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690545880917/bd125bac-104d-4b12-8b46-aad085ba0e79.png align="left")

To view the contents of a file, you can use the `cat` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690545896620/51b5d4d5-5d01-4689-95c0-20006aaaaeb6.png align="left")

### **6: Add Content to devopstools.txt**

To add content to the `devopstools.txt` file, we can use either the `vim` or `echo` command.

Using the `vim` command:

This will open the `devopstools.txt` file in the Vim text editor. Press `I` enter insert mode, then add the following tools, one per line:

* Jenkins
    
* ansible
    
* Docker
    
* K8S
    
* maven
    
* git
    
* terraform
    
* datadog
    
* slack
    
* selenium
    
* Once you've added the tools, press `Esc` to exit insert mode, then type `:wq` to save the changes and exit Vim.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690546256191/52971f55-b556-4323-adcd-1440ac0dbb3a.png align="left")

### **7: Show Only the Top Three tools from the File**

To show only the top three tools from the `devopstools.txt` file, we can use the `head` command with the `-n` option.

This command will display the first three lines (tools) from the file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690546375116/4ded5c10-c3f6-4f90-925d-782a0e6abbd1.png align="left")

### **8: Show Only the Bottom Three tools from the File**

To show only the bottom three tools from the `devopstools.txt` file, we can use the `tail` command with the `-n` option.:

This command will display the last three lines (tools) from the file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690546478389/14a69601-aac3-4314-a902-add147c6c31c.png align="left")

### **9: Create and View the Content of another File**

To create another file named `services.txt`, we can use the `touch` command:

Similarly, to view the contents of the `services.txt` file, you can use the `cat` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690552926519/5edd8383-e08f-43f0-be12-80eb8c38572a.png align="left")

### **10: Add Content to services.txt**

To add content to the `services.txt` file, we can use either the `vim` or `echo` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690552948538/61585794-0139-423f-8339-c1d8695479d3.png align="left")

### **11: Find the Difference between devopstools.txt and services.txt Files**

To find the difference between the contents of two files, such as `devopstools.txt` and `services.txt`, we can use the `diff` command. For example:

This command will display the differences between the two files, if any

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690553297706/2cb22861-001f-47d1-9490-0de8f45fd837.png align="left")

Conclusion:

Congratulations! You've learned some essential commands to navigate and manage directories and files in the Linux file system. The pwd command helps you determine your current location, while the ls command with the -a option enables you to list directories and files, including hidden ones. Additionally, you now know how to create nested directories efficiently using the mkdir command with the -p flag. Also, We covered important concepts related to Linux fundamentals, such as file manipulation, permissions, and comparing files. Continue exploring the Linux file system, and remember to practice these commands to become more proficient. Stay tuned for more exciting blogs, where we will go further into Linux concepts to continue our journey in the world of DevOps. Happy learning!

Thank you for reading, and happy Linux exploring!

`Let's learn together! I appreciate any comments or suggestions you may have to improve my blog content.`

Thank you,

Akshay Nazirkar
