🎯 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
| Term | What it means |
|---|---|
| Kernel | The core program that talks to hardware. This is the only part that is literally "Linux". |
| Operating system | The kernel plus the GNU utilities, shell, libraries and service manager that make it usable. |
| Distribution | An 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.
Distribution families
| Family | Members | Package | Manager | Typical use |
|---|---|---|---|---|
| Debian | Debian, Ubuntu, Mint | .deb | apt, dpkg | Cloud, containers, developer machines |
| Red Hat | RHEL, Rocky, AlmaLinux, Fedora | .rpm | dnf, rpm | Enterprise servers, regulated industries |
| SUSE | SLES, openSUSE | .rpm | zypper | Enterprise, strong in Europe |
| Arch | Arch, Manjaro | .pkg.tar.zst | pacman | Enthusiasts, rolling release |
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
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
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/
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
| Task | Debian / Ubuntu | RHEL / Rocky / Amazon Linux |
|---|---|---|
| Refresh index | sudo apt update | (automatic) |
| Install | sudo apt install nginx | sudo dnf install nginx |
| Remove | sudo apt remove nginx | sudo dnf remove nginx |
| Search | apt search nginx | dnf search nginx |
| List installed | dpkg -l | rpm -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.
The layout is standardised by the Filesystem Hierarchy Standard (FHS), which is why these directories mean the same thing on every distribution.
/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.
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.
| Keys | Action |
|---|---|
| i | Insert before the cursor |
| Esc | Back to normal mode |
| :w / :q / :wq | Save / quit / save and quit |
| :q! | Quit, discarding changes — the escape hatch |
| dd / yy / p | Delete line / copy line / paste |
| /word then n | Search, then next match |
| :%s/old/new/g | Replace throughout the file |
The three standard streams
| Stream | Number | Default destination |
|---|---|---|
| stdin | 0 | Keyboard |
| stdout | 1 | Screen |
| stderr | 2 | Screen |
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
> 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
# 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.
| Symbol | On a file | On a directory |
|---|---|---|
| r (4) | Read the contents | List the names inside |
| w (2) | Modify the contents | Create, delete or rename entries inside |
| x (1) | Execute it | Enter it and reach things inside |
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.
| Octal | Symbolic | Meaning |
|---|---|---|
| 755 | rwxr-xr-x | Owner full; everyone else read and execute. Scripts, directories. |
| 644 | rw-r--r-- | Owner read/write; others read. Normal files. |
| 600 | rw------- | Owner only. Private keys, credentials — including your EC2 .pem file. |
| 700 | rwx------ | Owner only, directory. |
| 777 | rwxrwxrwx | Everyone, 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
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.
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
| su | sudo | |
|---|---|---|
| Password needed | The target user's | Your own |
| Scope | A whole shell session | One command |
| Audit trail | Poor | Every command logged |
| Shared root password | Required | Not 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.