Home › Modules › Module 03

🐧 Module 03 · Linux Fundamentals

Linux Introduction and Distributions, the Command Line, the File System, Editors, Filters, Redirection, Users, Groups and Permissions

6 hours11 practice questions 5 sections

🎯 By the end of this module you should be able to…

  • Distinguish the Linux kernel, the operating system and a distribution.
  • State the design principles — everything is a file, small tools, text as the universal interface — and use them to explain later behaviour.
  • Navigate the filesystem and manage files confidently from the command line.
  • Read the Filesystem Hierarchy Standard and say what lives in /etc, /var, /proc and /home.
  • Use redirection and pipes to combine small tools into a useful report.
  • Search and transform text with grep, cut, sort, uniq, sed and awk.
  • Manage users and groups, and read and set permissions in both octal and symbolic form.

What Linux actually is

TermWhat it means
KernelThe core program that talks to hardware. This is the only part that is literally "Linux".
Operating systemThe kernel plus the GNU utilities, shell, libraries and service manager that make it usable.
DistributionAn OS packaged by an organisation, with a package manager, default software, release policy and support model.

Design principles — these explain almost everything else

📄 Everything is a file

Documents, directories, disks, keyboards, network sockets and running processes are all presented as files, so one small set of tools works on all of them. cat /proc/cpuinfo reads live hardware information as if it were a text file.

🔨 Small tools, one job each

sort only sorts, grep only searches, wc only counts. None of them knows about the others.

📝 Text is the universal interface

Because every tool reads and writes plain text, any tool's output can be any other tool's input. That is what makes pipes so powerful.

👥 Multi-user from day one

Linux always assumed several people share one machine. That is why permissions are so thoroughly built in — and why they matter on a server.

┌─────────────────────────────────────┐ │ Applications (browser, database, app) │ ├─────────────────────────────────────┤ │ Shell + Utilities (bash, ls, grep) │ ├─────────────────────────────────────┤ │ System libraries (glibc) │ ├─────────────────────────────────────┤ │ KERNEL │ │ processes · memory · devices · │ │ filesystems · networking │ ├─────────────────────────────────────┤ │ Hardware │ └─────────────────────────────────────┘

Distribution families

FamilyMembersPackageManagerTypical use
DebianDebian, Ubuntu, Mint.debapt, dpkgCloud, containers, developer machines
Red HatRHEL, Rocky, AlmaLinux, Fedora.rpmdnf, rpmEnterprise servers, regulated industries
SUSESLES, openSUSE.rpmzypperEnterprise, strong in Europe
ArchArch, Manjaro.pkg.tar.zstpacmanEnthusiasts, rolling release
The most common beginner error

Following a tutorial written for the wrong family — running apt install on RHEL, or yum on Ubuntu. Confirm which family the machine is first: cat /etc/os-release. Amazon Linux, which you will meet on EC2, is Red Hat family and uses dnf / yum.

The command line

$ ls -l -h /var/log │ │ │ └── argument (what to act on) │ └──┴───── options / flags (how to behave) └──────────── command (what to run)

Getting help — teach this first

man ls            # full manual: arrows to scroll, / to search, q to quit
ls --help         # quick summary
apropos copy      # search manuals by keyword
type cd           # builtin, alias or program?
which python3     # where is the executable?

Navigation and listing

pwd               # where am I?
cd /var/log       # absolute path
cd ..             # up one level
cd ~              # home directory
cd -              # back to the previous directory

ls -l             # long format: permissions, owner, size, date
ls -a             # include hidden files (those starting with .)
ls -lh            # human-readable sizes
ls -ltr           # oldest first — best for log directories
ls -ld /etc       # the directory itself, not its contents
-rw-r--r--. 1 priya staff 2048 Aug 25 10:30 report.txt │└───────┘ │ │ │ │ │ │ │ perms │ owner group size modified name │ link count └─ file type: - file d directory l symlink

Files and directories

touch notes.txt          mkdir -p a/b/c
cp file.txt backup.txt   cp -r dir1/ dir2/
mv old.txt new.txt       mv file.txt /tmp/
rm file.txt              rm -r directory/
There is no recycle bin

rm is permanent. Two habits worth insisting on: run ls with the same pattern before you run rm, and never type rm -rf $VAR/ where $VAR might be empty — if it is unset, that command becomes rm -rf /.

Viewing, searching, processes

cat file.txt      less file.txt     head -n 20 file.txt
tail -n 50 f.log  tail -f app.log   # follow a live log

find /home -name "*.txt"      find . -mtime -7
find /var -size +100M         locate report.pdf

ps aux | grep nginx           top
kill 1234                     kill -9 1234   # last resort
df -h     du -sh /var/log     free -h     uptime
TaskDebian / UbuntuRHEL / Rocky / Amazon Linux
Refresh indexsudo apt update(automatic)
Installsudo apt install nginxsudo dnf install nginx
Removesudo apt remove nginxsudo dnf remove nginx
Searchapt search nginxdnf search nginx
List installeddpkg -lrpm -qa

The file system

Windows gives each disk a letter. Linux has a single tree starting at /, and extra disks are mounted at a directory inside that tree.

/ ├── bin → essential user commands (ls, cp, cat) ├── boot → kernel and bootloader. Do not touch casually. ├── dev → device files (/dev/null, /dev/sda) ├── etc → system-wide configuration. Text files. ├── home → user home directories (/home/priya) ├── lib → shared libraries ├── mnt → manually mounted filesystems ├── opt → optional and third-party software ├── proc → virtual: live kernel and process information ├── root → the root USER's home. NOT the root of the tree. ├── sbin → system administration commands ├── tmp → temporary, world-writable, cleared on reboot ├── usr → most installed software └── var → data that grows: logs, mail, spool, caches └── log → where you will spend a lot of your time

The layout is standardised by the Filesystem Hierarchy Standard (FHS), which is why these directories mean the same thing on every distribution.

Two that catch everyone once

/root is the root user's home directory, not the root of the filesystem — that is /. And /proc and /sys are not on disk at all; the kernel generates them in memory, which is "everything is a file" made visible.

Links

ln  original.txt hardlink.txt      # second name for the same inode
ln -s /var/log/app.log ~/applog    # symbolic link — a file holding a path

A hard link is an equal second name; delete one and the data survives until the last name goes. It cannot cross filesystems. A symbolic link is a small file containing a path; it can cross filesystems and point at directories, but it breaks if the target disappears. In practice you will use symbolic links almost every time.

Extensions mean nothing

Linux does not use the file extension to decide what a file is. A file called report.txt could be a JPEG. Use file report.txt, which inspects the contents.

Editors, redirection, pipes and filters

Surviving vim

Vim is on every Unix system, including minimal containers and rescue shells. Even learners who prefer nano need enough vim to escape it.

KeysAction
iInsert before the cursor
EscBack to normal mode
:w / :q / :wqSave / quit / save and quit
:q!Quit, discarding changes — the escape hatch
dd / yy / pDelete line / copy line / paste
/word then nSearch, then next match
:%s/old/new/gReplace throughout the file

The three standard streams

StreamNumberDefault destination
stdin0Keyboard
stdout1Screen
stderr2Screen
ls > files.txt          # stdout to a file, OVERWRITING it
ls >> files.txt         # append instead
command 2> errors.txt   # stderr only
command > out.txt 2>&1  # both to the same file
command 2> /dev/null    # discard errors
Order matters

> out.txt 2>&1 means "send stdout to the file, then send stderr wherever stdout is going". Reversing it to 2>&1 > out.txt sends stderr to the screen, because at that moment stdout was still the screen.

Pipes — the payoff of the design principles

cat access.log | grep "404" | sort | uniq -c | sort -rn | head

Read it as: take the log, keep the 404 lines, sort them, count duplicates, sort by count descending, show the top ten. Five single-purpose tools composed into a report.

The filters worth memorising

grep -i "error" app.log     # case-insensitive
grep -v "debug" app.log     # invert: lines NOT matching
grep -rn "TODO" ./src       # recurse, with line numbers

cut -d: -f1 /etc/passwd     # field 1, colon-delimited → usernames
sort -n numbers.txt         # numeric — "10" after "9", not before
sort file.txt | uniq -c     # counts (uniq needs sorted input)
wc -l file.txt              # count lines

sed 's/old/new/g' file.txt  # replace every match
sed -i.bak 's/a/b/g' f.txt  # edit in place, keeping a backup

awk '{print $1}' file       # first field of every line
awk -F: '{print $1}' /etc/passwd
awk '{sum+=$2} END {print sum}' data.txt
Real one-liners you will reuse
# Top 10 IP addresses in a web log
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head

# Filesystems above 80% full
df -h | awk '$5+0 > 80 {print $6, $5}'

# Largest five files under /var
du -ah /var 2>/dev/null | sort -rh | head -5

Users, groups and permissions

Every process runs as some user, and every file belongs to a user and a group. Almost every real security incident on a Linux server traces back to something in this section being wrong.

-rwxr-xr-- 1 priya developers 2048 Aug 25 report.txt │└─┘└─┘└─┘ │ u g o └─ file type
SymbolOn a fileOn a directory
r (4)Read the contentsList the names inside
w (2)Modify the contentsCreate, delete or rename entries inside
x (1)Execute itEnter it and reach things inside
The directory column is the surprising one

w on a directory lets you delete files you do not own, because deletion changes the directory, not the file. That is exactly why /tmp needs the sticky bit.

OctalSymbolicMeaning
755rwxr-xr-xOwner full; everyone else read and execute. Scripts, directories.
644rw-r--r--Owner read/write; others read. Normal files.
600rw-------Owner only. Private keys, credentials — including your EC2 .pem file.
700rwx------Owner only, directory.
777rwxrwxrwxEveryone, everything. Almost always wrong.
chmod 755 script.sh        chmod u+x script.sh
chmod go-w file.txt        chmod -R 755 /var/www
chown priya:developers file.txt

useradd -m -s /bin/bash priya      passwd priya
usermod -aG developers priya       # -aG APPENDS
groupadd developers                id priya
The most damaging single character in this module

usermod -G replaces all secondary groups. usermod -aG appends. Omitting the a has locked administrators out of sudo on production servers.

Special permissions

SUID (4)

Runs as the file's owner. This is how an ordinary user can run passwd and write to root-only /etc/shadow. Audit them: find / -perm -4000 -type f

SGID (2)

On a directory, new files inside inherit the directory's group — genuinely useful for shared team folders.

Sticky bit (1)

Only the owner can delete. This is the t in drwxrwxrwt on /tmp.

chmod 777 is not a fix

It is the "turn it off and on again" of Linux: it makes the error go away and opens a hole. If a permission problem seems to need 777, the ownership is usually wrong instead.

su versus sudo

susudo
Password neededThe target user'sYour own
ScopeA whole shell sessionOne command
Audit trailPoorEvery command logged
Shared root passwordRequiredNot required

Servers prefer sudo because nobody needs the root password and every action is attributable to a person. Edit the rules with visudo, never a plain editor — it validates the syntax before saving.

Key takeaways

  • Kernel ≠ operating system ≠ distribution.
  • Everything is a file; small tools; text as the universal interface — these explain the rest.
  • /etc is configuration, /var/log is logs, /proc is the live kernel, /root is a home directory.
  • rm is permanent and > destroys a file. Prefer >> and check with ls first.
  • Pipes compose single-purpose tools into reports: grep | sort | uniq -c | sort -rn | head.
  • 755 for scripts and directories, 644 for files, 600 for keys. 777 is almost always a mistake.
  • usermod -aG appends; usermod -G wipes. Always include the a.

Quiz