Linux Fundamentals

Vishnu BongoniVishnu Bongoni
14 min read

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:

  1. Hardware Layer:

    This layer consists of Physical components of computer like CPU,RAM,DISK etc

    The OS interacts with hardware using device drivers

  2. 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.

  3. 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.

  4. 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

DistributionBased OnTarget Audience
UbuntuDebianBeginners, desktops, servers
DebianIndependentStability-focused users
FedoraRed HatDevelopers, cutting-edge users
CentOS / Alma Linux / Rocky LinuxRed HatServers, enterprise
Arch LinuxIndependentAdvanced users, DIY setups
ManjaroArchIntermediate users, easier Arch
Linux MintUbuntuNew Linux users, desktops
Kali LinuxDebianSecurity professionals
openSUSEIndependentDevelopers, power users
Pop!_OSUbuntuDevelopers, gamers

Folder Structure:

DirectoryDescription
/Root directory – the base of the entire Linux file system. All other files and folders branch from here.
/binEssential binaries – basic command-line programs needed for the system to boot and run (e.g., ls, cp, mv, bash).
/sbinSystem binaries – system administration commands (e.g., shutdown, reboot). Used mostly by the root user.
/etcConfiguration files – all system-wide configuration files live here (e.g., network settings, user accounts).
/homeUser directories – each user gets a folder here (e.g., /home/john) to store personal files.
/rootRoot user’s home – this is the home directory for the system's superuser (root).
/usrUser programs – contains applications and files for regular users. This is often the largest directory.
/usr/binNon-essential user commands (e.g., most software you install).
/usr/sbinNon-essential system admin commands.
/varVariable data – files that change often, like logs (/var/log), emails, or web content.
/tmpTemporary files – for short-lived data; often cleaned up at reboot.
/devDevice files – represents physical and virtual devices (e.g., /dev/sda for a hard disk).
/procProcess info – a virtual filesystem showing info about running processes and system status.
/sysSystem info – similar to /proc, but focuses on hardware and device management.
/libLibraries – shared libraries needed by binaries in /bin and /sbin.
/bootBoot files – contains the Linux kernel and bootloader files (like grub).
/media & /mntMount 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.

FilePurpose
/etc/passwdStores user account info (username, UID, home directory, etc.)
/etc/shadowStores encrypted passwords and password policies
/etc/groupDefines groups and which users belong to them
/etc/sudoersControls who can run commands as root (via sudo)

Basic User Management Commands:

TaskCommand
Add usersudo adduser username or sudo useradd username
Delete usersudo deluser username or sudo userdel username
Change passwordsudo passwd username
Modify usersudo usermod (e.g., to change shell, home dir, groups)
List userscat /etc/passwd or getent passwd
Switch usersu username or sudo -i (to become root)

Group Management:

TaskCommand
Create groupsudo groupadd groupname
Add user to groupsudo usermod -aG groupname username
View groups of a usergroups username
Delete groupsudo 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

  1. ls – Lists files and directories in the current location.

  2. cd /path/to/directory – Changes the working directory.

  3. pwd – Prints the current working directory.

  4. mkdir new_folder – Creates a new directory.

  5. rmdir empty_folder – Removes an empty directory.

  6. rm file.txt – Deletes a file.

  7. rm -r folder – Deletes a folder and its contents.

  8. cp file1.txt file2.txt – Copies a file.

  9. cp -r dir1 dir2 – Copies a directory recursively.

  10. mv old_name new_name – Moves or renames a file or directory.

File Viewing and Editing

  1. cat file.txt – Displays file content.

  2. tac file.txt – Displays file content in reverse order.

  3. less file.txt – Opens a file for viewing with scrolling support.

  4. more file.txt – Similar to less, but only moves forward.

  5. head -n 10 file.txt – Displays the first 10 lines of a file.

  6. tail -n 10 file.txt – Displays the last 10 lines of a file.

  7. nano file.txt – Opens a simple text editor.

  8. vi file.txt – Opens a powerful text editor.

  9. echo 'Hello' > file.txt – Writes text to a file, overwriting existing content.

  10. 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 left

  • l – Move right

  • j – Move down

  • k – Move up

  • 0 – Move to the beginning of the line

  • ^ – Move to the first non-blank character of the line

  • $ – Move to the end of the line

  • w – Move to the next word

  • b – Move to the previous word

  • gg – Move to the start of the file

  • G – Move to the end of the file

  • :n – Move to line number n


Insert Mode Shortcuts

  • i – Insert before cursor

  • I – Insert at the beginning of the line

  • a – Append after cursor

  • A – Append at the end of the line

  • o – Open a new line below

  • O – Open a new line above

  • Esc – Exit insert mode


Editing Text

  • x – Delete a character

  • X – Delete a character before cursor

  • dw – Delete a word

  • dd – Delete a line

  • d$ – Delete from cursor to end of line

  • d0 – Delete from cursor to beginning of line

  • D – Delete from cursor to end of line

  • u – Undo last action

  • Ctrl + r – Redo an undone change

  • yy – Copy (yank) a line

  • yw – Copy (yank) a word

  • p – Paste after the cursor

  • P – Paste before the cursor


Search and Replace

  • /pattern – Search forward for a pattern

  • ?pattern – Search backward for a pattern

  • n – Repeat last search forward

  • N – 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 vertically

  • Ctrl + 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--:

SymbolMeaning
-File type (- = file, d = directory, l = link)
rwxOwner permissions: Read, Write, Execute
r-xGroup 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

CategoryApplies To
Owner (User)The file’s creator or assigned user
GroupMembers of the file’s group
OthersAll 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

NumberPermissionMeaning
7rwxRead + Write + Execute
6rw-Read + Write
5r-xRead + Execute
4r--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

BitDescription
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

CommandDescriptionExample
psShows a snapshot of current processesps aux – detailed list of all processes
topReal-time view of running processes (interactive)Just run top
htopEnhanced top (more user-friendly; may need install)htop
pidofGets the PID (Process ID) of a processpidof firefox
pgrepFinds process by name and returns its PIDpgrep apache2

2. Getting Process Info

CommandDescription
ps -efDetailed info about all processes
ps -u usernameView processes for a specific user
ps -p PIDInfo about a specific process
lsof -p PIDLists files opened by a process
strace -p PIDTraces system calls and signals (useful for debugging)

3. Starting & Running Processes

CommandDescriptionExample
&Run process in backgroundgedit &
nohupRun process that won’t stop after logoutnohup myscript.sh &
niceStart a process with a given prioritynice -n 10 ./heavy_task.sh

4. Stopping / Killing Processes

CommandDescriptionExample
kill PIDSend a signal to a process (default: TERM)kill 1234
kill -9 PIDForce kill a process (SIGKILL)kill -9 1234
killall nameKill all processes by namekillall firefox
pkill nameKill by name using pattern matchingpkill apache
xkillClick a GUI window to kill it (used in desktops)Run xkill and click the window

5. Managing Background/Foreground Jobs

CommandDescriptionExample
jobsList jobs running in the background of the current terminal
fgBring background job to foregroundfg %1
bgResume a suspended job in backgroundbg %1
Ctrl + ZPause (suspend) a foreground job
&Run command in backgroundsleep 100 &

6. Process Priorities – nice and renice

CommandDescriptionExample
nice -n 10 commandStart with lower priority (default is 0, range -20 to 19)
renice -n 5 -p PIDChange priority of a running processrenice -n 5 -p 1234

Lower value = higher priority. -20 is highest, 19 is lowest.


🔧 7. System Resource Monitoring

CommandWhat It Does
vmstatReports memory, swap, processes
iostatCPU and disk I/O stats
free -hShows memory usage
uptimeShows system uptime and load average
sarCollects, 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 monitoring

  • htop – Interactive process viewer (requires installation)

  • vmstat – Report system performance statistics

  • free -m – Show memory usage

Disk Monitoring

  • df -h – Check disk space usage

  • du -sh /path – Show disk usage of a specific directory

  • iostat – Display CPU and disk I/O statistics

Network Monitoring

  • ifconfig – Show network interfaces (deprecated, use ip a)

  • ip a – Show network interface details

  • netstat -tulnp – Show active connections and listening ports

  • ss -tulnp – Alternative to netstat for socket statistics

  • ping hostname – Test network connectivity

  • traceroute hostname – Show network path to a host

  • nslookup domain – Get DNS resolution details

Log Monitoring

  • tail -f /var/log/syslog – Live monitoring of system logs

  • journalctl -f – Live system logs for systemd-based distros

  • dmesg | tail – View kernel logs

Networking Commands:

  1. ping google.com – Checks connectivity to a remote server.

  2. ifconfig – Displays network interfaces (deprecated, use ip).

  3. ip a – Shows IP addresses of network interfaces.

  4. netstat -tulnp – Displays open network connections.

  5. curl https://example.com – Fetches a webpage's content.

  6. 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 devices

  • fdisk -l – List disk partitions

  • blkid – Show UUIDs of devices

  • df -h – Check disk space usage

  • du -sh /path – Show size of a directory

Partition Management

  • fdisk /dev/sdX – Create and manage partitions

  • parted /dev/sdX – Alternative to fdisk for GPT disks

  • mkfs.ext4 /dev/sdX1 – Format a partition as ext4

  • mkfs.xfs /dev/sdX1 – Format a partition as XFS

Mounting and Unmounting

  • mount /dev/sdX1 /mnt – Mount a partition

  • umount /mnt – Unmount a partition

  • mount -o remount,rw /mnt – Remount a partition as read-write

Logical Volume Management (LVM)

  • pvcreate /dev/sdX – Create a physical volume

  • vgcreate vg_name /dev/sdX – Create a volume group

  • lvcreate -L 10G -n lv_name vg_name – Create a logical volume

  • mkfs.ext4 /dev/vg_name/lv_name – Format an LVM partition

  • mount /dev/vg_name/lv_name /mnt – Mount an LVM partition

Swap Management

  • mkswap /dev/sdX – Create a swap partition

  • swapon /dev/sdX – Enable swap space

  • swapoff /dev/sdX – Disable swap space

0
Subscribe to my newsletter

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

Written by

Vishnu Bongoni
Vishnu Bongoni