Linux Essentials

Introduction

Welcome to this beginner-friendly guide on Linux essentials. In this post, we'll cover the fundamental concepts and commands you need to get started with Linux. Whether you're new to Linux or just looking to brush up on your skills, this guide will provide a solid foundation. We'll explore everything from the basics of the Linux kernel and shell to essential commands and user management. Let's dive in!

Why Linux?

Linux Penguin Mascot Tux up close

Linux is a versatile, open-source operating system known for its robustness, security, and efficiency. It powers a significant portion of the internet's infrastructure, including servers, supercomputers, and embedded systems. Here's why Linux is essential:

  • Stability and Performance: Linux systems are stable and perform well under heavy loads, making them ideal for development and production environments.

  • Security: Linux offers robust security features, such as user permissions and built-in firewalls.

  • Flexibility: Linux can be customized to meet specific needs, with a wide range of distributions and software packages available.

  • Community Support: A large, active community provides support, documentation, and a wealth of open-source tools.

What is the Kernel and Shell?

Kernel

The kernel is the core of the Linux operating system, responsible for managing system resources and facilitating communication between hardware and software. It handles tasks such as:

  • Memory Management: Allocating and deallocating memory for processes.

  • Process Management: Scheduling and managing processes.

  • File System Management: Handling data storage, retrieval, and organization.

  • Device Management: Managing hardware devices and drivers.

Shell

The shell is a command-line interface that allows users to interact with the operating system. It interprets user commands and communicates them to the kernel. Popular shells include:

  • Bash (Bourne Again Shell): The default shell on many Linux distributions.

  • Zsh (Z Shell): Known for its powerful features and user-friendly configuration.

  • Fish (Friendly Interactive Shell): Offers user-friendly syntax highlighting and auto-suggestions.

Basic Commands in Linux

Getting Started Commands

  1. echo $0

    • Prints the current shell name.

    • Example:

        echo $0
      

      If you are using Bash, this command will return bash.

  2. touch

    • Creates a new empty file.

    • Example:

        touch example.txt
      

      This will create an empty file named example.txt in the current directory.

  3. ls

    • Lists files and directories.

    • Example:

        ls example.txt
      

      This command will list the details of example.txt if it exists in the current directory.

  4. mv <new_filename>

    • Moves or renames files and directories.

    • Example:

        mv example.txt new_example.txt
      

      This will rename example.txt to new_example.txt.

  5. cp <new_filename>

    • Copies files and directories.

    • Example:

        cp example.txt copy_example.txt
      

      This will create a copy of example.txt named copy_example.txt.

  6. pwd

    • Prints the current working directory.

    • Example:

        pwd
      

      This command will display the full path of the current directory.

  7. ls -lart

    • Lists files and directories with detailed information, sorted by modification time.

    • Example:

        ls -lart
      

      This will display a detailed list of files and directories, including hidden ones, sorted by their modification time.

  8. ls -a

    • Lists all files, including hidden files.

    • Example:

        ls -a
      

      This will show all files and directories in the current directory, including those that are hidden (names starting with a dot).

  9. ls -R

    • Lists files and directories recursively.

    • Example:

        ls -R
      

      This will list all files and directories in the current directory and all subdirectories.

  10. history

    • Shows the history of commands entered.

    • Useful for recalling previously executed commands.

    • Example:

        history
      

      This will display a numbered list of previously entered commands.

Additional Useful Commands

  1. cat

    • Concatenates and displays the content of a file.

    • Example:

        cat example.txt
      

      This will print the contents of example.txt to the terminal.

  2. rm

    • Removes (deletes) a file.

    • Example:

        rm example.txt
      

      This will delete example.txt from the current directory.

  3. mkdir <directory_name>

    • Creates a new directory.

    • Example:

        mkdir my_directory
      

      This will create a directory named my_directory.

  4. rmdir <directory_name>

    • Removes an empty directory.

    • Example:

        rmdir my_directory
      

      This will remove the directory my_directory if it is empty.

  5. grep

    • Searches for a pattern in a file and displays matching lines.

    • Example:

        grep "search_term" example.txt
      

      This will search for search_term in example.txt and display any lines containing that term.

  6. chmod

    • Changes the permissions of a file or directory.

    • Example:

        chmod 755 example.txt
      

      This will set the permissions of example.txt to 755 (read and execute for everyone, write for the owner).

  7. chown :

    • Changes the owner and group of a file or directory.

    • Example:

        chown user:group example.txt
      

      This will change the owner of example.txt to user and the group to group.

Package Management

  1. sudo apt-get update

    • Updates the list of available packages and their versions.

    • This command fetches the latest list of packages from the repositories, ensuring that your package manager knows about the latest versions.

    • Example:

        sudo apt-get update
      
  2. sudo apt-get upgrade

    • Installs the latest versions of all packages currently installed.

    • This command upgrades all the packages on your system to their latest versions, based on the updated package list.

    • Example:

        sudo apt-get upgrade
      
  3. sudo apt-get install <package_name>

    • Installs a package.

    • Example:

        sudo apt-get install curl
      
  4. sudo apt-get remove <package_name>

    • Removes a package.

    • Example:

        sudo apt-get remove curl
      

Installing a Package or Application

What Is the APT Package Manager: Why and How To Use It

Installing packages or applications in Ubuntu is straightforward using the APT (Advanced Package Tool) package management system. The APT package manager simplifies the process of installing, updating, and removing software. To install a package, you typically use the sudo apt-get install command followed by the package name.

For example, to install curl, a popular command-line tool for transferring data with URLs, you would open a terminal and type:

sudo apt-get update
sudo apt-get install curl
  1. Update the package list: This ensures you have the latest information about available packages.

     sudo apt-get update
    
  2. Install curl: This command fetches the curl package from the repositories and installs it on your system.

     sudo apt-get install curl
    

Alternatively, if you want to install WhatsApp (which isn't typically available directly through APT), you might use a snap package:

  1. Install snapd (if not already installed):

     sudo apt-get install snapd
    
  2. Install WhatsApp using Snap:

     sudo snap install whatsapp-for-linux
    

These commands show how to install different types of software on Ubuntu, utilizing both APT and Snap package managers, ensuring flexibility and a broad range of available applications.

Users in Linux

  1. Regular User

    • Has limited permissions, typically used for everyday tasks.

    • Example: Creating files in the home directory.

        useradd regular_user
      
  2. Root User

    • Has full administrative permissions, can perform any task on the system.

    • Example: Installing software or modifying system files.

        sudo su
      
  3. Service User

    • Used by system services and daemons.

    • Typically does not have login permissions.

    • Example:

        useradd --system service_user
      

Absolute vs. Relative Path

  • Absolute Path

    • The full path to a file or directory from the root directory.

    • Example:

        /home/user/documents/example.txt
      
  • Relative Path

    • The path to a file or directory relative to the current working directory.

    • Example:

        documents/example.txt
      

Conclusion

In this blog, we covered the basics of Linux, including the kernel and shell, essential commands, package management, and user management. We also explored the difference between absolute and relative paths. This knowledge forms a crucial foundation for working effectively in a Linux environment.

Did you find this article valuable?

Support Kanishk's Kaleidoscope by becoming a sponsor. Any amount is appreciated!