Understanding Linux: A Comprehensive Guide

Statistically, 96% of humans are not using Linux. This is unfortunate, as Linux is a superior, free, open-source operating system, but it only has a 4% share of the PC market. However, 96% of the non-human bots are using Linux because it is the dominant OS on servers. If you are a programmer or developer, you need to know Linux—that’s where your code will eventually run and fail. If you can’t SSH into a Linux terminal and fix it, you are in trouble.

In this article, we’ll cover everything you need to know about Linux by exploring 101 essential concepts. By the end, you’ll have a deeper understanding of Linux and be able to talk tech like an experienced user.

The Origins of Linux

Before one can understand Linux, it’s important to recognize what came before it: Unix. Unix, an operating system developed at AT&T Bell Labs in the 1970s, led to the standardization called POSIX (Portable Operating System Interface) to ensure that different systems would be compatible with each other. Its influence remains strong today, with macOS, Android, FreeBSD, and most Linux distributions being POSIX-compliant.

In 1987, an OS called Minix was developed for academic use, but the redistribution of its code was restricted. This inspired a Finnish computer science student to develop Linux in 1991. Importantly, Linux is free, open-source software licensed under GPL 2.0. By “free,” we mean it is free to distribute, modify, and even make money off of.

The Linux Kernel

Linux itself is not an operating system but rather an operating system kernel. Written in the C programming language, it acts as the intermediary between software applications and hardware. When you power on your computer, the boot loader (usually GRUB) loads the Linux kernel into random access memory. From there, it detects hardware and starts the init system (typically systemd, though alternatives exist). Once initialized, the kernel starts up applications in user space, bringing the user to a login screen.

As the user starts interacting, the kernel manages memory for processes, creating virtual memory when needed by tapping into the hard drive. Speaking of the hard drive, the kernel provides a virtual file system to interact with files. The fourth extended file system (ext4) is the most common default on Linux, but it’s not the only option. The kernel also interacts with peripheral devices via drivers.

System Calls and User Privileges

Users can’t directly interact with the kernel because it’s surrounded by the CPU’s protection ring. At ring zero, we have the kernel with the highest level of privilege, while user space lives in ring three with the lowest level of privilege. However, actions requiring kernel access, like writing a file to the file system, are facilitated by system calls. For instance, a system call to write can transition from ring three to ring zero to output text to the console.

GNU, a project that predates the Linux kernel, provides core utilities that make the kernel useful. To start exploring these core utilities, open up the terminal, a graphical user interface that allows command input via the shell. The most common shell is Bash.

Basic Commands and Utilities

Let’s say hello to the Linux kernel by running the GNU shell utility echo and providing a string argument. This command prints the message to the standard output. What happens under the hood is that a system call is made to the kernel, which checks permissions and manages drivers to turn those ones and zeros into pixels on the screen.

If you’re unsure about a command, you can pull up the manual using the man command. For example, man touch reveals that the touch command creates a new file. Running touch followed by a file name creates a file, and using ls lists the files in the directory. The cat command can read file contents, while stat provides metadata like timestamps.

Combining commands is a powerful feature of the Linux terminal. For example, echo "hello" > file.txt redirects the output to a new file. Using pipes (|), the output of one command can be passed to another, like sorting a log file line by line.

Scripting and Text Editors

If repetitive tasks become cumbersome, writing a bash script can automate them. To create a script, use a text editor like Nano, Vim, or Emacs. Start the script with a shebang (#!/bin/bash) to specify the bash interpreter, and add your commands. Save the file and execute it by entering the file path in the terminal.

Advanced Topics and Customization

To become proficient in Linux, understanding file permissions is crucial. Use ls -l to view permissions. Symbolic permissions consist of nine characters representing read, write, and execute privileges for the owner, group, and others. Permissions can also be represented as numbers in octal notation, like 777, which allows everyone to do anything with the file.

Modify permissions using chmod, change file ownership with chown, and assign groups with chgrp. Each command or program creates a process managed by the Linux kernel. View these processes with ps or htop for an interactive breakdown. Background processes can be created with an ampersand (&), and scheduled tasks can be set up using crontab.

Linux distributions, or distros, vary widely, each with a set of default software for their target audience. Distros can have different package managers like yum and pacman, and different release schedules. Desktop environments like GNOME or KDE Plasma significantly impact the user experience.

Some major distros include Slackware, Debian, Red Hat, and Arch. Each has its strengths and caters to different user needs.

Conclusion

This guide provides a high-level overview of Linux, but there’s so much more to learn. For those seeking deeper knowledge, consider exploring comprehensive Linux courses and hands-on practice. Linux is a powerful, versatile operating system that, once mastered, can significantly enhance your programming and development skills.

Thanks for reading! If you want to dive deeper, check out more resources and tutorials. Happy learning, and welcome to the world of Linux!