Linux Basics and Commands
Subject: Computer Science Fundamentals · Language: Operating System · Level: advanced · 10 min read
Learn Linux basics, shell, terminal, file system paths, permissions, users, package managers, processes, and essential beginner commands.
Linux is an open-source operating system used in servers, cloud systems, development machines, cybersecurity labs, embedded devices, Android-based systems, and many technical environments. It is important for students because many real-world tools, coding platforms, deployment systems, and backend servers use Linux or Linux-like commands. Linux is not only one operating system in a narrow sense. It is built around the Linux kernel, and different groups create complete operating system distributions around it. These distributions include system tools, package managers, desktop environments, utilities, and default applications.
For beginners, Linux can be understood as a powerful operating system where users can control the system through both graphical interfaces and command-line tools. The command line is especially important because it gives direct and precise control over files, processes, software, and system settings.
Why Linux Is Important
Linux is widely used on servers because it is stable, flexible, secure, and efficient. Many websites, APIs, databases, cloud platforms, and DevOps tools run on Linux machines. Students who learn Linux commands can work more comfortably with programming tools, Git, Docker, cloud servers, deployment pipelines, and development environments. Linux knowledge also helps in operating system study because many OS concepts such as files, permissions, processes, shells, and users can be observed practically through commands.
Linux Kernel
The kernel is the core part of an operating system. In Linux, the kernel manages CPU scheduling, memory, processes, device drivers, file systems, networking, and system calls. User programs do not directly control hardware. They request services from the kernel through system calls. This keeps the system safe and organized. When people say Linux, they often mean a complete Linux distribution, but technically Linux refers to the kernel at the center of the system.
Linux Distribution
A Linux distribution, also called a distro, is a complete operating system built using the Linux kernel and additional software. Examples include Ubuntu, Debian, Fedora, Arch Linux, Linux Mint, Kali Linux, and Red Hat Enterprise Linux. Different distributions may use different package managers, default tools, update systems, and user interfaces, but many basic commands remain similar.
Terminal
The terminal is an application that lets users type commands and see text-based output. It is a way to communicate with the operating system using commands instead of clicking through menus. For example, instead of opening a file manager to create a folder, a user can type a command to create it immediately. The terminal is useful because it is fast, repeatable, scriptable, and available on servers where graphical interfaces may not be installed.
Shell
A shell is a program that reads commands typed by the user, interprets them, and asks the operating system to perform the required action. Common shells include Bash, Zsh, Fish, and Dash. Bash is one of the most common shells for beginners and is widely used in Linux tutorials. The terminal is the window or interface, while the shell is the program running inside it that understands commands.
Command Structure
Most Linux commands follow a simple structure: command name, options, and arguments. The command name tells what action to perform. Options modify the behavior. Arguments tell the command what item to work on. For example, in `ls -l /home`, `ls` is the command, `-l` is an option, and `/home` is the argument. Options often start with a hyphen. Short options may look like `-l`, while long options may look like `--help`.
Current Directory
The current directory is the folder where the shell is currently working. Commands often act relative to this location. The command `pwd` prints the current working directory. It helps users know where they are inside the file system. This is important because a command may fail or affect the wrong file if it is run from an unexpected directory.
Listing Files
The `ls` command lists files and directories. It is one of the first commands beginners learn. `ls` shows the contents of the current directory. `ls -l` shows detailed information such as permissions, owner, size, and modification time. `ls -a` also shows hidden files. Hidden files in Linux usually start with a dot, such as `.bashrc` or `.gitignore`.
Changing Directory
The `cd` command changes the current directory. It allows the user to move through the file system. For example, `cd Documents` moves into the Documents directory if it exists inside the current location. `cd ..` moves one level up to the parent directory. The command `cd ~` moves to the current user's home directory. The home directory is where a user's personal files and settings are usually stored.
Absolute and Relative Paths
An absolute path starts from the root directory and gives the complete location of a file or folder. For example, `/home/student/notes/os.txt` is an absolute path. A relative path starts from the current directory. For example, if the user is already inside `/home/student`, then `notes/os.txt` can refer to the same file. Understanding paths is necessary because many Linux commands require correct file or folder locations.
Root Directory
The root directory is the top of the Linux file system and is represented by `/`. Every file and folder is located under this root directory. Common directories include `/home`, `/bin`, `/etc`, `/var`, `/tmp`, `/usr`, and `/root`. Linux does not use drive letters like Windows. Instead, devices and partitions are mounted somewhere inside the single directory tree.
Creating Files and Directories
The `mkdir` command creates a directory. For example, `mkdir notes` creates a folder named notes. The `touch` command can create an empty file or update a file's timestamp. For example, `touch intro.txt` creates an empty text file if it does not already exist. These commands are useful when organizing project folders, notes, scripts, and configuration files.
Copying, Moving, and Renaming
The `cp` command copies files or directories. For example, `cp a.txt b.txt` creates a copy of `a.txt` named `b.txt`. The `mv` command moves or renames files. For example, `mv old.txt new.txt` renames the file. `mv file.txt Documents` moves the file into the Documents directory. The same command is used for moving and renaming because both operations change the file's location or name in the file system.
Removing Files and Directories
The `rm` command removes files. For example, `rm old.txt` deletes a file named old.txt. The `rmdir` command removes an empty directory. To remove a directory with contents, Linux commonly uses `rm -r`, but this must be used carefully because it deletes recursively. Beginners should be cautious with delete commands. Linux may not always ask for confirmation, and deleted files may not go to a recycle bin depending on the command and environment.
Viewing File Content
The `cat` command prints the full content of a file. It is useful for small files. The `less` command allows scrolling through larger files. It is better than `cat` when a file has many lines. The `head` command shows the first lines of a file, while `tail` shows the last lines. `tail -f` is often used to watch log files as they update.
Searching Text
The `grep` command searches for text patterns inside files. For example, `grep error app.log` searches for lines containing the word error. Grep is useful for reading logs, finding code references, checking configuration files, and filtering command output. It becomes even more powerful when combined with pipes, because output from one command can be searched by another command.
Pipes
A pipe sends the output of one command as input to another command. The pipe symbol is `|`. For example, `ls -l | grep txt` lists detailed files and then filters only lines containing `txt`. Pipes are a key reason Linux commands are powerful. Small commands can be combined to perform larger tasks.
Redirection
Redirection sends command output to a file or takes input from a file. The `>` symbol writes output to a file, replacing old content. The `>>` symbol appends output to the end of a file. For example, `echo Hello > message.txt` writes Hello into message.txt. `echo Again >> message.txt` adds another line without removing existing content. Redirection is useful for saving command results, creating simple files, and building scripts.
File Permissions
Linux uses permissions to control who can read, write, or execute files. The common permission types are read, write, and execute. Read permission allows viewing file content. Write permission allows modifying the file. Execute permission allows running a file as a program or entering a directory. Permissions are usually assigned for three categories: owner, group, and others.
Understanding Permission Letters
When `ls -l` is used, permissions may appear like `rwxr-xr--`. These letters show access rights. `r` means read, `w` means write, and `x` means execute. A dash means that permission is not given. The first group belongs to the owner, the second group belongs to the group, and the third group belongs to others.
chmod Command
The `chmod` command changes file permissions. It can use symbolic notation or numeric notation. For example, `chmod +x script.sh` adds execute permission to a script. This is commonly needed before running shell scripts. Numeric permissions such as `755` or `644` are also common. Beginners should first understand read, write, and execute before memorizing numbers.
Users and Groups
Linux is a multi-user operating system. Each user has an account, and users can belong to groups. Groups make permission management easier. Instead of giving access to many users one by one, the system can give access to a group. Commands such as `whoami` show the current user, and `groups` shows the groups of the current user.
sudo
The `sudo` command allows an authorized user to run a command with administrative privileges. It is commonly used when changing system settings or installing software. For example, installing packages or editing protected system files may require `sudo`. Sudo should be used carefully because administrative commands can affect the entire system.
Package Manager
A package manager installs, updates, and removes software. Different Linux distributions use different package managers. Ubuntu and Debian commonly use `apt`. Fedora uses `dnf`. Arch Linux uses `pacman`. Package managers are useful because they download software from trusted repositories and also handle required dependencies.
Processes in Linux
A process is a running program. Linux provides commands to view and manage processes. The `ps` command shows running processes. The `top` command shows live system activity such as CPU usage, memory usage, and active processes. The `kill` command can send signals to a process. Despite the name, it does not only terminate processes; it sends signals, and termination is one common signal use.
Background and Foreground Jobs
A foreground job runs directly in the terminal and occupies it until the command finishes. A background job runs while the terminal remains available for other commands. Adding `&` at the end of a command can start it in the background. The `jobs` command shows background jobs started from the current shell. This is useful when running long tasks while still using the terminal.
Environment Variables
Environment variables store information used by the shell and programs. For example, `PATH` tells the shell where to search for executable commands. The `echo $PATH` command prints the PATH variable. The `export` command can create or update environment variables for the current shell session. Environment variables are common in development because projects often use them for configuration such as API URLs, ports, and secret keys.
Shell Scripts
A shell script is a file containing shell commands. It allows repeated tasks to be automated. For example, instead of typing many commands to build and deploy a project, a developer can place those commands inside a script and run the script when needed. Shell scripting is useful for automation, backups, setup tasks, deployment, log processing, and system administration.
Logs
Linux systems store many logs that help users and administrators understand what is happening. Logs may record system startup, application errors, login attempts, service activity, and security events. Log files are often stored under `/var/log`. Commands such as `cat`, `less`, `tail`, and `grep` are commonly used to inspect them. Logs are important for troubleshooting. When something fails, checking logs often gives the first clue.
Networking Commands
Linux provides commands to check network status and connectivity. The `ping` command checks whether another host is reachable. Commands such as `ip`, `curl`, `wget`, and `ssh` are commonly used in networking and server work. `ssh` is especially important because it allows secure remote login to another machine, such as a cloud server.
Help Commands
Linux includes built-in help systems. The `man` command opens manual pages for commands. For example, `man ls` shows detailed help for `ls`. Many commands also support `--help`, which prints usage information and common options. Beginners should build the habit of checking help instead of trying to memorize every option at once.
Common Beginner Commands
Some useful beginner commands are `pwd`, `ls`, `cd`, `mkdir`, `touch`, `cp`, `mv`, `rm`, `cat`, `less`, `head`, `tail`, `grep`, `chmod`, `whoami`, `ps`, `top`, and `man`. These commands cover navigation, file handling, text viewing, searching, permissions, process checking, and help. A student does not need to master every Linux command immediately. It is better to understand a small group clearly and then learn more commands as real needs appear.
Linux in Development
Linux is heavily used in software development because many tools are designed for Unix-like environments. Git, compilers, package managers, Docker, servers, and cloud tools are commonly used through Linux commands. Even if a student uses Windows, learning Linux commands is useful because many deployment servers and coding environments use Linux. This is why Linux basics are often included in computer science, backend development, DevOps, cybersecurity, and placement preparation.
Summary
Linux is an important operating system family built around the Linux kernel. It is widely used because it is stable, powerful, flexible, and suitable for servers and development. For beginners, the most important areas are terminal usage, shell commands, file paths, permissions, users, processes, package managers, logs, and basic networking commands. These concepts make it easier to work with real systems and understand operating system behavior practically.
More Operating System Lessons
- Introduction to Operating System
- Types of Operating System
- Operating System Functions and Services
- System Calls in Operating System
- Process Management in Operating System
- Process Scheduling in Operating System
- CPU Scheduling Algorithms
- Threads and Multithreading in Operating System
- Process Synchronization in Operating System
- Deadlock in Operating System
- Memory Management in Operating System
- Virtual Memory in Operating System