#90DaysOfDevOps - Day 2: Linux and its basic commands

ยท

7 min read

Welcome to Day 2 of #90DaysOfDevOps! Today, we embark on a journey to explore the Linux operating system, delving into its intricacies and mastering a few fundamental commands. ๐Ÿš€๐Ÿง

Linux

Linux ๐Ÿง is an open-source operating system created by Linus Torvalds in 1991. ๐ŸŒ It boasts a flexible, customizable, and powerful ๐Ÿ› ๏ธ platform that empowers users to access, modify, and distribute its source code freely. With its strong community support ๐Ÿค and a vast array of software packages, Linux has become a dominant force in web servers, supercomputers, cloud infrastructure, smartphones, and IoT devices. ๐Ÿ’ป๐Ÿ“ฑ Its reputation for security, stability, and innovation ๐Ÿ›ก๏ธ๐Ÿ”ง has won the trust of businesses and individuals alike. Linux represents the spirit of collaboration and democratization of technology ๐ŸŒˆ๐ŸŒ, symbolizing the power of collective efforts in reshaping the digital landscape. ๐Ÿš€

Architecture

Linux architecture serves as the foundation for various Linux-based operating systems and is designed with flexibility and modularity in mind. ๐Ÿ—๏ธ

At its core, the Linux architecture consists of the following components:

๐Ÿ  Kernel: The heart of Linux, responsible for core functions, memory management, processes, and device drivers. It acts as an interface between software and hardware.

๐Ÿ“ฆ File System: Organizes data and programs into files and directories, using a hierarchical structure for efficient storage and retrieval.

๐Ÿ”Œ Device Drivers: Facilitate communication between the kernel and hardware devices, ensuring compatibility with diverse hardware.

๐Ÿ“‹ System Calls: Enable programs to request services from the kernel, such as file operations or process management.

๐Ÿ›๏ธ Libraries: Provide precompiled functions that applications can use, simplifying access to system functions.

๐Ÿ’ป Shell and Command-Line Interface: The shell, or command-line interpreter, allows users to execute commands, manage files, and run programs efficiently.

๐Ÿ–ฅ๏ธ Processes and Threads: Processes represent running programs, while threads enable multitasking and parallel execution within processes.

๐ŸŒ Networking Stack: Manages networking operations, including TCP/IP protocols and socket communication, facilitating network connectivity for applications.

๐Ÿ” Security Modules: Implement security features like access control, encryption, and authentication, enhancing the overall system security.

Linux in DevOps

Linux ๐Ÿง plays a pivotal role in DevOps practices, acting as a backbone for seamless collaboration, automation, and scalability. As an open-source operating system, Linux enables developers and operations teams to customize and automate processes, reducing manual intervention and minimizing errors. It serves as the preferred platform for various DevOps tools, such as Ansible, Docker, and Kubernetes, facilitating efficient configuration management, containerization, and orchestration. Linux's stability, security features, and vast community support contribute to creating reliable and secure development and deployment environments. Overall, Linux empowers DevOps teams to streamline workflows, accelerate continuous integration and continuous deployment (CI/CD) pipelines, and drive innovation in software development. ๐Ÿš€๐Ÿ’ป๐Ÿ”ง

Linux directory structure under root (/)

In Linux, the root directory (/) contains various standard directories that serve specific purposes and store essential files and subdirectories. Some of these directories are:

๐Ÿ—ƒ๏ธ /bin: Contains essential binary executables and commands. Example: /bin/ls - This command lists the contents of the current directory. ๐Ÿ“‚๐Ÿ”

๐Ÿš€ /boot: Stores files related to the boot process. Example: /boot/vmlinuz-5.4.0-86-generic - The Linux kernel file used during the boot process. ๐Ÿง๐Ÿ”Œ

๐Ÿ“Ÿ /dev: Represents device files for accessing connected devices. Example: /dev/sda - Represents the first hard disk drive in the system. ๐Ÿ’ฝ๐Ÿ’ป

๐Ÿ”ง /etc: Holds system-wide configuration files. Example: /etc/resolv.conf - Contains DNS server configuration for the system. โš™๏ธ๐Ÿ“

๐Ÿ  /home: Contains user home directories. Example: /home/john - Home directory for the user "john." ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿก

๐Ÿ“š /lib and /lib64: Contain essential system libraries. Example: /lib/x86_64-linux-gnu/libc.so.6 - C library used by many programs. ๐Ÿ“š๐Ÿ”ง

๐Ÿ’ฟ /media: Used for temporarily mounting external media. Example: /media/usb-drive - A mount point for a USB drive. ๐Ÿ“€๐Ÿ”Œ

๐Ÿ“ /mnt: Used for temporarily mounting other file systems or network shares. Example: /mnt/network-share - A mount point for a network shared folder. ๐ŸŒ๐Ÿ”Œ

๐Ÿฌ /opt: Used for installing additional software from third-party vendors. Example: /opt/google/chrome - The installation directory for Google Chrome browser. ๐Ÿฌ๐ŸŒ

๐Ÿ”„ /proc: A virtual file system providing information about system processes. Example: /proc/cpuinfo - Contains information about the CPU and its features. ๐Ÿ”„๐Ÿ“Š

๐Ÿ‘‘ /root: The home directory for the root user. Example: /root/.bashrc - The bash configuration file for the root user. ๐Ÿง™โ€โ™‚๏ธ๐Ÿฐ

โณ /run: Contains temporary runtime files created by services. Example: /run/utmp - Keeps track of current login sessions. โณ๐Ÿƒ

โš™๏ธ /sbin: Contains system administration binaries. Example: /sbin/ifconfig - A command to configure network interfaces. โš™๏ธ๐Ÿ”ง

๐Ÿข /srv: Intended to hold site-specific data served by the system. Example: /srv/www - Holds website data served by the web server. ๐Ÿข๐ŸŒ

๐Ÿ—‘๏ธ /tmp: Used for temporary files. Example: /tmp/tempfile.txt - A temporary file created by an application. ๐Ÿ—‘๏ธ๐Ÿ”ฅ

๐Ÿ“ฆ /usr: Contains user-related files and applications. Example: /usr/bin/gcc - The GCC compiler binary. ๐Ÿ“ฆ๐Ÿ‘จโ€๐Ÿ’ป

๐Ÿ“ /var: Holds variable data, such as log files and temporary data. Example: /var/log/syslog - Contains system log messages. ๐Ÿ“๐Ÿ“

These directories form the essential structure of the Linux file system, each serving specific purposes and contributing to the overall functionality and organization of the operating system. ๐ŸŒŸ๐Ÿง

Now, let's get started with some hands-on tasks that cover basic Linux commands. ๐Ÿ“‚๐Ÿ“‹๐Ÿ“ฆ๐Ÿ’ป"

Tasks

Check your present working directory.

Use pwd (present working directory) to display the current directory of the present directory of user i.e. /home/ubuntu

Create a new directory called "practice_folder."

Use mkdir command to create a new directory practise_folder. Use ls command to display the contents of the current directory to verify that practise_folder directory is created.

Create three directories named "dir1," "dir2," and "dir3" in one go.

Use mkdir to create multiple directories dir1 dir2 and dir3 in one command by separating them with space.

Create a nested directory structure with directories A, B, C, D, and E inside each other.

Use the -p option with mkdir to create nested directory A/B/C/D/E. Use the tree command to display the directory structure of the current directory to verify the nested directory.

Enter the "practice_folder" directory you created earlier.

Use the ls command to check where is the practise_folder. Use the cd command to move into the practise_folder.

Move back to the parent directory from "practice_folder."

Use cd with .. to move to the parent directory of practise_folder.

Move to your home directory from anywhere in the file system.

Use cd with ~ or just enter cd to move to your home directory /home/ubuntu from anywhere in the file system (here it's moving from practise_folder).

List all the files and directories in your current working directory.

Use the ls command to list all the files and directories in the current working directory.

List all files and directories, including hidden files (files/folders whose names start with a dot).

Use the -a option with ls command to display all the files and directories along with hidden files. The hidden files start with a dot . like .bash_history shown in the output.

List files and directories in the current working directory with detailed information, including permissions, owner, group, size, and modification date.

Use the -l option with the ls command to list files and directories in the current working directory with detailed information, including permissions, owner, group, size, modification date, and name.

List files and directories in a specific directory.

Use the ls command along with the specific directory path i.e. /home/ubuntu to list files and directories of /home/ubuntu.

List files and directories in the current directory, sorted by size (largest to smallest).

Use the -S option with ls command to list files and directories in the current directory, sorted by size (largest to smallest). We can combine two options of the same command. Here we have combined -l and -S option.

List files and directories in the current directory, sorted by modification time (most recent first).

Use the -t option with ls command to list files and directories in the current directory, sorted by modification time (most recent first).

Conclusion

๐Ÿ“š Today, we have delved into the fascinating world of the Linux operating system! ๐Ÿง We explored its architecture and discovered its pivotal role in the DevOps ecosystem. ๐Ÿ’ป To add some excitement, we wrapped up with hands-on experience using basic commands: pwd, mkdir, cd, and ls. ๐Ÿƒโ€โ™‚๏ธ I hope this journey was a great start to your Linux learning adventure! ๐Ÿš€๐ŸŒŸ

"๐ŸŒฑ Keep learning, and spread the knowledge to inspire others. ๐Ÿš€๐Ÿ’ก"

ย