Day-6-devops

Understanding Linux and Shell Scripting: A Comprehensive Guide

What is an Operating System?

Before we dive into Linux, it's essential to understand what an operating system (OS) is. An OS acts as a bridge between the hardware of a computer and the software applications that run on it. For instance, when you purchase a laptop or a server, you acquire hardware components like the CPU, RAM, and hard disk. To utilize this hardware, you need software applications, whether for gaming, development, or productivity.

However, software cannot directly communicate with hardware. This is where the operating system comes into play, facilitating communication between the two. Whether you are using a Windows OS or a Linux OS, the operating system is crucial for managing hardware resources and enabling software functionality.

Linux has gained immense popularity, especially in production environments. Here are some reasons why:

  1. Free and Open Source: Unlike Windows, which is a proprietary operating system, Linux is free and open-source. This allows anyone to create Unix-like operating systems based on Linux.

  2. Security: Linux is known for its robust security features. Users often do not need to install antivirus software, as Linux is inherently secure.

  3. Speed: Linux is designed to be fast and efficient, making it ideal for production systems where performance is critical.

These factors contribute to Linux being the preferred choice for many developers and organizations.

Architecture of Linux Operating System

Understanding the architecture of Linux is vital. Here’s a simplified breakdown:

  • Kernel: The core component of the OS, responsible for managing communication between hardware and software. It handles device management, memory management, process management, and system calls.

  • System Libraries: These libraries provide essential functions for applications. For example, the libc library is a standard C library used in many Linux distributions.

  • User Processes and System Software: These include compilers and other software that users interact with.

Fundamentals of Shell Scripting

Shell scripting is a way to communicate with the operating system through command-line instructions. Unlike graphical user interfaces, shell commands allow users to perform tasks directly in the terminal, which is crucial for managing servers without a GUI.

Basic Shell Commands

Here are some essential shell commands that every user should know:

  1. pwd: Displays the present working directory.

  2. ls: Lists files and directories in the current directory.

  3. ls -ltr: compete details of file with created timestamp, size.. .

  4. cd: Changes the current directory.

  5. touch <filename>: Creates a new file.

  6. vi <filename>: Creating and opens a file for editing. (esc+i→writing/inserting text), (wq! →to save edited file)

  7. mkdir <filename>: Creates a new directory.

  8. rm - r <filename>: Removes files or directories.

  9. df -h: Displays disk space usage.

  10. free -g: Shows memory usage.

  11. nproc : Number of cpu

  12. top: Provides a dynamic view of system processes, including CPU and memory usage.

Example Usage of Commands

  • To check your current directory, use:

      pwd
    
  • To list files, use:

      ls
    
  • To create a new file, use:

      touch filename.txt
    
  • To edit a file, use:

      vi filename.txt
    

Navigating Directories

To navigate through directories:

  • Use cd to change directories. For example, to move to a directory named "bundle":

      cd bundle
    
  • To go back one directory, use:

      cd ..
    

Conclusion

In this post, we explored the fundamentals of the Linux operating system and shell scripting. We discussed the role of the OS, the advantages of using Linux, and essential shell commands for effective system management. Understanding these concepts is crucial for anyone looking to excel in DevOps or system administration.

For those eager to learn more, I have created additional videos covering shell scripting in detail, including intermediate concepts and practical applications. Stay tuned for our next session, where we will discuss a real-time DevOps project using shell scripting. If you found this information helpful, please like and share this post with others interested in learning DevOps.