Linux Fundamentals

Linux is a operating system just like Windows, mac etc. Linux share similarities with Unix which is another operating system has comparable components. Linux is open-source Operating system which is free to use, and its source code is available for anyone to view, modify, and distribute. Linux is known for being stable, secure, and customizable, and is widely used for servers, desktops, and embedded systems.
Core Components of Linux:
Hardware Layer:
This layer consists of Physical components of computer like CPU,RAM,DISK etc
The OS interacts with hardware using device drivers
Kernel:
The kernel is the core of the Linux operating system. It acts as an interface between hardware and software. It manages system resources, such as the CPU, memory, and I/O devices. The kernel controls how programs interact with hardware and ensures efficient multitasking and security.
Shell:
The shell is a command-line interface (CLI) that allows users to interact with the operating system. It interprets commands typed by the user and communicates with the kernel to execute them. Examples include Bash (Bourne Again Shell) and Zsh.
User Applications:
It is the tool you use on a Linux system to get work done—whether it's browsing the web, coding, watching videos, or editing documents. They depend on the underlying Linux components (like the kernel and libraries) but provide the features and interfaces that make the system usable and productive for everyday tasks.
Linux Distributions:
A Linux Distribution also called Distros are different versions of linux that pacakge complete operating system built around the linux kernel. It includes the kernel, system libraries, utilities, software management tools (like package managers), and often a desktop environment or other user applications. Some of the popular linux distributions are
Distribution | Based On | Target Audience |
Ubuntu | Debian | Beginners, desktops, servers |
Debian | Independent | Stability-focused users |
Fedora | Red Hat | Developers, cutting-edge users |
CentOS / Alma Linux / Rocky Linux | Red Hat | Servers, enterprise |
Arch Linux | Independent | Advanced users, DIY setups |
Manjaro | Arch | Intermediate users, easier Arch |
Linux Mint | Ubuntu | New Linux users, desktops |
Kali Linux | Debian | Security professionals |
openSUSE | Independent | Developers, power users |
Pop!_OS | Ubuntu | Developers, gamers |
Folder Structure:
Directory | Description |
/ | Root directory – the base of the entire Linux file system. All other files and folders branch from here. |
/bin | Essential binaries – basic command-line programs needed for the system to boot and run (e.g., ls , cp , mv , bash ). |
/sbin | System binaries – system administration commands (e.g., shutdown , reboot ). Used mostly by the root user. |
/etc | Configuration files – all system-wide configuration files live here (e.g., network settings, user accounts). |
/home | User directories – each user gets a folder here (e.g., /home/john ) to store personal files. |
/root | Root user’s home – this is the home directory for the system's superuser (root ). |
/usr | User programs – contains applications and files for regular users. This is often the largest directory. |
/usr/bin | Non-essential user commands (e.g., most software you install). |
/usr/sbin | Non-essential system admin commands. |
/var | Variable data – files that change often, like logs (/var/log ), emails, or web content. |
/tmp | Temporary files – for short-lived data; often cleaned up at reboot. |
/dev | Device files – represents physical and virtual devices (e.g., /dev/sda for a hard disk). |
/proc | Process info – a virtual filesystem showing info about running processes and system status. |
/sys | System info – similar to /proc , but focuses on hardware and device management. |
/lib | Libraries – shared libraries needed by binaries in /bin and /sbin . |
/boot | Boot files – contains the Linux kernel and bootloader files (like grub ). |
/media & /mnt | Mount points – for external drives, USBs, and other temporary mounts. |
User Management:
User management in Linux is all about controlling who can access the system, what they can do, and how resources are shared. It involves creating users, setting permissions, managing groups, and securing user accounts.
File | Purpose |
/etc/passwd | Stores user account info (username, UID, home directory, etc.) |
/etc/shadow | Stores encrypted passwords and password policies |
/etc/group | Defines groups and which users belong to them |
/etc/sudoers | Controls who can run commands as root (via sudo ) |
Basic User Management Commands:
Task | Command |
Add user | sudo adduser username or sudo useradd username |
Delete user | sudo deluser username or sudo userdel username |
Change password | sudo passwd username |
Modify user | sudo usermod (e.g., to change shell, home dir, groups) |
List users | cat /etc/passwd or getent passwd |
Switch user | su username or sudo -i (to become root) |
Group Management:
Task | Command |
Create group | sudo groupadd groupname |
Add user to group | sudo usermod -aG groupname username |
View groups of a user | groups username |
Delete group | sudo groupdel groupname |
File Management:
File management in Linux is all about creating, moving, copying, deleting, and organizing files and directories using the command line (or GUI tools). Since everything in Linux is treated as a file, mastering file management is essential.
File and Directory Management
ls
– Lists files and directories in the current location.cd /path/to/directory
– Changes the working directory.pwd
– Prints the current working directory.mkdir new_folder
– Creates a new directory.rmdir empty_folder
– Removes an empty directory.rm file.txt
– Deletes a file.rm -r folder
– Deletes a folder and its contents.cp file1.txt file2.txt
– Copies a file.cp -r dir1 dir2
– Copies a directory recursively.mv old_name new_name
– Moves or renames a file or directory.
File Viewing and Editing
cat file.txt
– Displays file content.tac file.txt
– Displays file content in reverse order.less file.txt
– Opens a file for viewing with scrolling support.more file.txt
– Similar toless
, but only moves forward.head -n 10 file.txt
– Displays the first 10 lines of a file.tail -n 10 file.txt
– Displays the last 10 lines of a file.nano file.txt
– Opens a simple text editor.vi file.txt
– Opens a powerful text editor.echo 'Hello' > file.txt
– Writes text to a file, overwriting existing content.echo 'Hello' >> file.txt
– Appends text to a file without overwriting.
Using VI Editor:
Modes in VI Editor
Normal Mode (default) – Used for navigation and command execution.
Insert Mode – Used for text editing (press
i
to enter,Esc
to exit).Command Mode – Used for saving, quitting, and searching (press
:
in Normal mode).
Basic Navigation
h
– Move leftl
– Move rightj
– Move downk
– Move up0
– Move to the beginning of the line^
– Move to the first non-blank character of the line$
– Move to the end of the linew
– Move to the next wordb
– Move to the previous wordgg
– Move to the start of the fileG
– Move to the end of the file:n
– Move to line numbern
Insert Mode Shortcuts
i
– Insert before cursorI
– Insert at the beginning of the linea
– Append after cursorA
– Append at the end of the lineo
– Open a new line belowO
– Open a new line aboveEsc
– Exit insert mode
Editing Text
x
– Delete a characterX
– Delete a character before cursordw
– Delete a worddd
– Delete a lined$
– Delete from cursor to end of lined0
– Delete from cursor to beginning of lineD
– Delete from cursor to end of lineu
– Undo last actionCtrl + r
– Redo an undone changeyy
– Copy (yank) a lineyw
– Copy (yank) a wordp
– Paste after the cursorP
– Paste before the cursor
Search and Replace
/pattern
– Search forward for a pattern?pattern
– Search backward for a patternn
– Repeat last search forwardN
– Repeat last search backward:%s/old/new/g
– Replace all occurrences of "old" with "new":s/old/new/g
– Replace all occurrences in the current line
Working with Multiple Files
:e filename
– Open a new file:w
– Save file:wq
– Save and exit:q!
– Quit without saving:split filename
– Split screen horizontally and open another file:vsplit filename
– Split screen verticallyCtrl + w + w
– Switch between split screens
File Permissions in Linux:
File permissions control who can read, write, or execute a file or directory. It's a core part of Linux security and user management.
1. Understanding Permission Notation
Use ls -l
to view file permissions:
bashCopyEdit-rwxr-xr-- 1 user group 1234 Apr 23 10:00 example.sh
Breakdown of -rwxr-xr--
:
Symbol | Meaning |
- | File type (- = file, d = directory, l = link) |
rwx | Owner permissions: Read, Write, Execute |
r-x | Group permissions: Read, Execute |
r-- | Others (everyone else): Read only |
So, this file:
Can be read, written, and executed by the owner.
Can be read and executed by the group.
Can only be read by others.
2. Permission Categories
Category | Applies To |
Owner (User) | The file’s creator or assigned user |
Group | Members of the file’s group |
Others | All other users on the system |
3. Changing Permissions – chmod
You can set permissions using symbolic or numeric (octal) notation.
✅ Symbolic Mode
bashCopyEditchmod u+x file.txt # Add execute for owner (u = user)
chmod g-w file.txt # Remove write for group
chmod o=r file.txt # Set read-only for others
✅ Numeric Mode
Number | Permission | Meaning |
7 | rwx | Read + Write + Execute |
6 | rw- | Read + Write |
5 | r-x | Read + Execute |
4 | r-- | Read only |
0 | --- | No permissions |
Example:
bashCopyEditchmod 755 script.sh
# = rwx (7) for owner
# = r-x (5) for group
# = r-x (5) for others
4. Changing Owner or Group – chown
and chgrp
bashCopyEditchown newuser file.txt # Change file owner
chown user:group file.txt # Change owner and group
chgrp newgroup file.txt # Change group only
5. Special Permission Bits
Bit | Description |
s (Setuid) | Run the file with the owner's privileges |
s (Setgid) | Files: run with group’s privileges; Directories: new files inherit group |
t (Sticky bit) | Only owner/root can delete files in the directory (common in /tmp ) |
Set with chmod
, e.g.:
bashCopyEditchmod +t /sharedfolder # Add sticky bit
chmod 4755 program # Setuid (4), normal 755 permissions
Process Management:
In Linux, process management means monitoring, controlling, starting, stopping, and managing the programs (a.k.a. processes) running on your system. Below is a full list of commonly used process management commands, with explanations and examples.
1. Viewing Running Processes
Command | Description | Example |
ps | Shows a snapshot of current processes | ps aux – detailed list of all processes |
top | Real-time view of running processes (interactive) | Just run top |
htop | Enhanced top (more user-friendly; may need install) | htop |
pidof | Gets the PID (Process ID) of a process | pidof firefox |
pgrep | Finds process by name and returns its PID | pgrep apache2 |
2. Getting Process Info
Command | Description |
ps -ef | Detailed info about all processes |
ps -u username | View processes for a specific user |
ps -p PID | Info about a specific process |
lsof -p PID | Lists files opened by a process |
strace -p PID | Traces system calls and signals (useful for debugging) |
3. Starting & Running Processes
Command | Description | Example |
& | Run process in background | gedit & |
nohup | Run process that won’t stop after logout | nohup myscript.sh & |
nice | Start a process with a given priority | nice -n 10 ./heavy_ task.sh |
4. Stopping / Killing Processes
Command | Description | Example |
kill PID | Send a signal to a process (default: TERM) | kill 1234 |
kill -9 PID | Force kill a process (SIGKILL) | kill -9 1234 |
killall name | Kill all processes by name | killall firefox |
pkill name | Kill by name using pattern matching | pkill apache |
xkill | Click a GUI window to kill it (used in desktops) | Run xkill and click the window |
5. Managing Background/Foreground Jobs
Command | Description | Example |
jobs | List jobs running in the background of the current terminal | |
fg | Bring background job to foreground | fg %1 |
bg | Resume a suspended job in background | bg %1 |
Ctrl + Z | Pause (suspend) a foreground job | |
& | Run command in background | sleep 100 & |
6. Process Priorities – nice
and renice
Command | Description | Example |
nice -n 10 command | Start with lower priority (default is 0, range -20 to 19) | |
renice -n 5 -p PID | Change priority of a running process | renice -n 5 -p 1234 |
Lower value = higher priority. -20
is highest, 19
is lowest.
🔧 7. System Resource Monitoring
Command | What It Does |
vmstat | Reports memory, swap, processes |
iostat | CPU and disk I/O stats |
free -h | Shows memory usage |
uptime | Shows system uptime and load average |
sar | Collects, reports, or saves system activity info (may require sysstat ) |
System Monitoring:
Linux system monitoring is the process of observing and analyzing various system resources to ensure the system is running efficiently and to detect issues early. It's crucial for system administrators and developers to keep servers or development environments stable, secure, and performant.
Index of Commands Covered
CPU and Memory Monitoring
top
– Real-time system monitoringhtop
– Interactive process viewer (requires installation)vmstat
– Report system performance statisticsfree -m
– Show memory usage
Disk Monitoring
df -h
– Check disk space usagedu -sh /path
– Show disk usage of a specific directoryiostat
– Display CPU and disk I/O statistics
Network Monitoring
ifconfig
– Show network interfaces (deprecated, useip a
)ip a
– Show network interface detailsnetstat -tulnp
– Show active connections and listening portsss -tulnp
– Alternative tonetstat
for socket statisticsping hostname
– Test network connectivitytraceroute hostname
– Show network path to a hostnslookup domain
– Get DNS resolution details
Log Monitoring
tail -f /var/log/syslog
– Live monitoring of system logsjournalctl -f
– Live system logs for systemd-based distrosdmesg | tail
– View kernel logs
Networking Commands:
ping
google.com
– Checks connectivity to a remote server.ifconfig
– Displays network interfaces (deprecated, useip
).ip a
– Shows IP addresses of network interfaces.netstat -tulnp
– Displays open network connections.curl
https://example.com
– Fetches a webpage's content.wget
https://example.com/file.zip
– Downloads a file from the internet.
Disk Management:
Managing disks and storage efficiently is crucial for system performance and stability. Linux provides various commands to monitor, partition, format, mount, and manage disk storage.
Index of Commands Covered
Viewing Disk Information
lsblk
– Display block devicesfdisk -l
– List disk partitionsblkid
– Show UUIDs of devicesdf -h
– Check disk space usagedu -sh /path
– Show size of a directory
Partition Management
fdisk /dev/sdX
– Create and manage partitionsparted /dev/sdX
– Alternative tofdisk
for GPT disksmkfs.ext4 /dev/sdX1
– Format a partition as ext4mkfs.xfs /dev/sdX1
– Format a partition as XFS
Mounting and Unmounting
mount /dev/sdX1 /mnt
– Mount a partitionumount /mnt
– Unmount a partitionmount -o remount,rw /mnt
– Remount a partition as read-write
Logical Volume Management (LVM)
pvcreate /dev/sdX
– Create a physical volumevgcreate vg_name /dev/sdX
– Create a volume grouplvcreate -L 10G -n lv_name vg_name
– Create a logical volumemkfs.ext4 /dev/vg_name/lv_name
– Format an LVM partitionmount /dev/vg_name/lv_name /mnt
– Mount an LVM partition
Swap Management
mkswap /dev/sdX
– Create a swap partitionswapon /dev/sdX
– Enable swap spaceswapoff /dev/sdX
– Disable swap space
Subscribe to my newsletter
Read articles from Vishnu Bongoni directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
