Day 1 - Linux Basics & Commands

Aman SharmaAman Sharma
5 min read

What is Linux?

Linux is an operating system, just like Microsoft Windows and Apple’s iOS and macOS. It is an open-source, Unix-like operating system kernel that serves as the core software, managing hardware resources and enabling software to run on computers.

Linux Components and Key Features

Kernel

At its core, Linux is a kernel responsible for managing the system's hardware, including the CPU, memory, storage, and peripheral devices. It provides an interface between software and hardware, allowing efficient communication.

Open Source

Linux is free and open-source software, meaning its source code is publicly available. Developers can study, modify, and distribute the code, contributing to its popularity and widespread adoption.

Modular and Flexible

Linux is highly customizable. Users can choose components based on their needs, such as different desktop environments, package managers, or services. This flexibility makes it suitable for a wide variety of systems, from servers and supercomputers to embedded devices and smartphones (like Android).

Multi-User and Multitasking

Linux supports multiple users simultaneously, ensuring that each user operates independently. It can also run multiple processes at the same time, allowing for efficient use of system resources.

File System and Permissions

Linux employs a hierarchical file system that organizes files and directories. It has a robust permission system that controls access to files and resources, providing strong security for users and administrators.

Distributions

Various distributions package the Linux kernel with additional software to meet different needs. Some distributions are designed for general use (e.g., Ubuntu for desktop users), while others are optimized for servers (e.g., Red Hat Enterprise Linux, CentOS) or specialized tasks.

Security

Linux is known for its high security and stability. Many servers, supercomputers, and web infrastructures run on Linux because it is less prone to malware, has a strong user permission system, and can run for extended periods without crashing.

In summary, Linux is a versatile, secure, and powerful operating system that powers a wide range of devices, from personal computers to servers and embedded systems. Its open-source nature allows for continuous development and extensive customization.

Top Linux Commands for DevOps

File Handling and Directory Management

  • pwd: Displays the present working directory.

  • touch: Creates an empty file.

  • mkdir: Creates a folder/directory.

  • rm: Removes a file or directory.

  • rmdir: Removes an empty directory.

  • cd: Navigates between different directories.

  • cp: Copies files or directories.

  • mv: Moves or renames files or directories.

  • find: Searches for files or directories.

  • ls: Lists all contents in the present working directory.

File Access and Operations

  • grep: Searches for a particular word in a text file.

  • head: Prints the first lines of a file (default: 10 lines).

  • tail: Prints the last lines of a file (default: 10 lines).

  • sed: Stream Editor for selecting, substituting, modifying text, and more.

  • sort: Sorts a file, arranging the records in a specified order.

  • cat: Views file contents, combines files, and creates new files.

  • nano: A versatile and user-friendly text editor for creating new files.

Access Control or User Privileges

  • chmod: Alters the access authorization of files and directories.

  • chown: Changes the ownership of files.

  • sudo: Runs commands with elevated privileges as a superuser.

  • id: Displays information about a user’s identity (UID, GID, and group memberships).

  • passwd: Changes user passwords.

  • useradd: Adds new users.

  • userdel: Deletes existing users.

System Administration

  • df: Displays disk space utilization.

  • du: Displays directory space utilization.

  • ps: Shows running processes.

  • top: A powerful tool for real-time information about system processes and resource usage.

  • htop: A more user-friendly version of the top command.

  • free: Displays memory utilization.

  • kill: Sends signals to processes, most commonly to terminate them.

  • systemctl: Manages services (starting, stopping, restarting) and controls system states (shutdown, reboot, etc.).

  • uptime: Shows the total time since the machine was last rebooted.

Networking in Linux

  • telnet: Connects to a remote Linux computer to execute programs remotely.

  • ifconfig/ip: Configures and manages network interfaces.

  • netstat: Obtains live network statistics.

  • ping: Tests the reachability of a host, helping determine if a device is online.

  • ssh: Securely connects to remote servers.

  • scp: Securely transfers files and directories between hosts using SSH.

  • traceroute: Traces the path that packets take to a specified destination, measuring latency and routing issues. Measures the time taken for each hop (among routers), helping to identify network latency and routing issues.

  • curl/wget: Downloads and transfers data over various protocols (HTTP, HTTPS, FTP, etc.).

Diagnostics and Monitoring (Logs)

  • journalctl: Displays system logs, including kernel messages and user applications.

  • dmesg: Useful for diagnosing hardware issues and driver problems.

  • tcpdump: Captures and analyzes network traffic for troubleshooting and security analysis.

Checking Log Files

To check log files, navigate to /var/log/syslog or /var/log/messages using the cd command.

Package Handling

  • apt (Advanced Package Tool): Manages .deb packages.

    • Used by: Debian, Ubuntu, Linux Mint, and other Debian-based distributions.

    • Package Format: DEB (Debian Package).

  • yum or dnf (and rpm directly): Manage .rpm packages.

    • Used by: Red Hat, CentOS, Fedora, openSUSE, and other Red Hat-based distributions.

    • Package Format: RPM (Red Hat Package Manager).

Common APT Commands

  • apt list: Displays information about packages available from the repositories, as well as packages already installed on the system

  • apt update: Updates the package index to prevent issues caused by outdated package lists.

  • apt install <package>: Installs software packages (e.g., apt install nginx curl wget -y).

  • apt remove <package>: Uninstalls a software package without deleting its configuration files.

  • apt purge <package>: Removes both the package and its configuration files.

  • apt search <package>: Searches for software packages in the repositories. It helps users find packages by name, description, or other metadata without having to install them.


Conclusion

Linux is a powerful and versatile operating system with a rich set of commands that can enhance productivity, especially for DevOps professionals. Whether you're managing files, administering systems, or troubleshooting network issues, mastering these commands will help you navigate and manage your Linux environment effectively.

I will add more commands and basic concepts related to Linux for DevOps in my next post. Please follow me and drop a comment if you liked the blog.

Thanks

1
Subscribe to my newsletter

Read articles from Aman Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aman Sharma
Aman Sharma

Passionate about simplifying the complexities of DevOps, I bring 1.5 years of hands-on experience in cloud infrastructure management. I excel at optimizing testing and staging environments for pre-production runs, automating workflows, and troubleshooting challenges across diverse cloud environments. My expertise includes infrastructure management, containerization with Docker, API-based CRM integration, and performance monitoring - ensuring stability and efficiency at every stage of the software lifecycle. Always eager to learn, collaborate, and innovate, I am committed to driving impactful change in the DevOps space.