UNIX Semester 2 - TP1 to TP9, explained like you are 5

The Ultimate Linux Resume

Linux is not magic. It is a big school: rooms, drawers, teachers, guards, notebooks, and tiny workers. This page turns every TP file in this workspace into one simple revision website.

🧭

Find your room

pwd, ls, cd, man pages, FHS.

Wake the machine

GRUB, kernel, initrd, systemd, targets.

📦

Install boxes

dpkg, apt, yum, zypper.

🧃

Pipes are straws

stdin, stdout, stderr, redirection, tee, xargs.

🛡️

Protect files

chmod, owners, groups, sticky, setuid, setgid.

🏃

Processes are runners

ps, top, signals, jobs, screen, tmux.

🧱

Disks are toy boxes

Partitions, filesystems, swap, mount, XFS, LVM.

⚠️

Exam traps

Wrong assumptions that make correct-looking commands fail.

Linux Basics: Know Where You Are

Before touching files, you must know the room you are standing in. If you skip this, every later command becomes guesswork.

🏠 Imagine Linux as a big house

The command line is you walking inside the house. pwd says "you are here". ls opens your eyes. cd moves your feet. man is the instruction book.

pwd # print the current room ls -la # list everything, even hidden toys cd .. # go to the parent room man 1 pwd # read the manual for pwd
Bad logic to kill now "I know ls, so I know Linux" is false. ls only shows objects. Linux skill means knowing paths, permissions, owners, devices, processes, and services.

📚 Man pages are bookshelves

man is split into sections. User commands live in section 1, system calls in section 2, C library functions in section 3, file formats in section 5, admin tools in section 8.

5-year-old version If two toys have the same name, the section tells you which toy box to open.

🗂️ FHS is the house map

/ is the front door. /home is users' bedrooms. /etc is the rule book. /bin and /usr/bin hold tools. /var is where changing things like logs live.

Exam shortcut If it configures the system, think /etc. If it changes all the time, think /var. If it is personal, think /home.

🔎 Useful ls patterns

QuestionCommandSimple idea
Long detailsls -lShow owner, group, size, date, permissions.
Hidden files tools -laShow the secret files starting with a dot.
Newest firstls -ltSort by time, newest on top.
Oldest firstls -ltrReverse the time order.
Six-character namesls ??????Each ? is exactly one character.
Starts with D or dls [Dd]*Use brackets for choices.

Boot: How Linux Wakes Up

A powered-off machine is asleep. Booting is the morning routine that brings it to life.

The wake-up chain

BIOS/UEFI GRUB Kernel initrd systemd
  1. Firmware checks the body.
    BIOS/UEFI checks hardware and finds something bootable.
  2. GRUB chooses the brain.
    GRUB loads the selected Linux kernel and can enter edit or command mode.
  3. Kernel becomes boss of hardware.
    It manages CPU, memory, devices, and mounts the first root environment.
  4. PID 1 starts the city.
    systemd starts services and targets.

🧰 Systemd tools

NeedCommandELI5 meaning
See processesps -ef, pstree -pWho is awake, and who woke them up?
Read kernel messagesdmesg, journalctl -kRead the machine's morning diary.
Manage servicesystemctl status nginxAsk if the web-server worker is okay.
Change targetsystemctl isolate multi-user.targetSwitch to another system mood.
Shutdownshutdown -h nowTell everyone: stop now.
Reboot at midnightshutdown -r 00:00 "message"Schedule a restart and warn users.
GRUB correction Do not edit /boot/grub/grub.cfg as your normal plan. The cleaner source is /etc/default/grub, then regenerate with update-grub or grub-mkconfig.

Kernel, Devices, and Shared Libraries

Linux has real files and fake-looking files that are actually windows into the kernel. Do not confuse them.

🧠 Kernel info

uname tells you about the kernel. lscpu tells you about the CPU. /proc and /sys are not normal folders; they are live reports from the kernel.

uname -v uname -a lscpu cat /proc/modules lsmod

🧩 Modules

A module is a plug-in for the kernel. Load it when needed; remove it when not needed. Example: ip_tables helps firewall rules.

modinfo ip_tables modinfo -a ip_tables sudo modprobe -r ip_tables sudo modprobe ip_tables

🔌 Devices are represented as files

/dev/sda is a disk-like block device. /dev/tty is a character device. udev creates device nodes dynamically when hardware appears.

ToolUseSimple image
lspci -vShow PCI devicesLook at big internal cards.
lspci -kShow kernel driversWhich teacher handles each card?
lsusb -vShow USB devicesLook at things plugged into USB.
lsusb -tShow USB treeDraw the USB family tree.

📦 Shared libraries

Programs often borrow common code from .so files. That saves memory, like many children using one big box of crayons instead of each child buying a box.

Runtime check

ldd /sbin/init lists libraries required by the executable.

Library map

ldconfig -p reads the linker cache, built from config such as /etc/ld.so.conf.

Do not abuse LD_LIBRARY_PATH It is temporary and can make programs load the wrong library. Use it for tests, not as your lazy permanent fix.

Packages: Installing Toys Without Breaking the Room

A package is a prepared box of software. The package manager knows where files go and what extra boxes are needed.

📦 dpkg vs apt

dpkg

It installs a local .deb file, but it is not smart about fetching missing dependencies.

sudo dpkg -i discord.deb

apt

It talks to repositories and solves dependency chains. Use this when possible.

sudo apt install ./discord.deb

Professor warning If dpkg fails because dependencies are missing, repeating the same command is not strategy. Use apt to resolve the missing boxes.

🛒 Debian package commands

TaskCommand
List installed packagesdpkg -l
Show files inside a package filedpkg -c discord.deb
List files installed by a packagedpkg -L discord
Remove, keep configsudo apt remove discord
Remove with configsudo apt purge discord
Clean unused dependenciessudo apt autoremove
Search packagesapt-cache search htop
Show dependenciesapt-cache depends htop

🌍 Other distributions

Ubuntu uses Debian-style tools. Red Hat uses RPM/YUM. openSUSE uses Zypper. Same goal, different language.

FamilyLow-levelSmart managerExample
Debian/Ubuntudpkgapt, aptitudeapt install htop
Red Hat/Fedorarpmyumyum install htop
openSUSERPM basezypperzypper install htop

Shell: Talking to Linux Clearly

The shell is not just typing commands. It is variables, children shells, input/output streams, and search tools.

🧃 Streams are straws

A command has three straws: stdin 0 drinks input, stdout 1 spits normal output, and stderr 2 spits errors.

command stdin 0 stdout 1 stderr 2
ls > lsfile # stdout to file ls -e 2> errorfile # stderr to file ls > all.txt 2>&1 # stdout and stderr together ls /usr/bin | nl # pipe output into another command ls | tee lsfile # show and save

🎒 Variables

MY_VAR=value stays in the current shell. export MY_VAR=value gives the variable to child shells too.

Common mistake A non-exported variable is like a toy you keep in your hand. Your child shell cannot play with it.

🕵️ Finding things

find searches live. locate searches a database. which checks PATH. type tells if something is builtin, alias, function, or binary.

find . -name "*.sh" sudo find / -maxdepth 4 -name "*.log" locate -i mytestfile whereis -b init which -a chmod type cp ls pwd

Text Filters: Tiny Machines in a Factory

Each filter does one small job. The power comes from combining them.

🏭 The text factory

ToolJobExample
catPrint or join filescat a b > c
lessRead big files page by pageless /etc/passwd
head / tailStart or end of filetail -n 20 /etc/passwd
nlNumber linesnl -b a testfile1
wcCount words, lines, byteswc -l /etc/passwd
odShow bytes as characters/hexod -c /etc/passwd
sortSort linessort -t, -k1,1n testfile
trTranslate/delete charstr ',' ';'
cutTake columnscut -d',' -f4 testfile
pastePut files side by sidepaste -d',' a b
uniqCollapse repeated neighborssort f | uniq -c
sedEdit stream textsed 's/Employee/Lawyer/g'
Important uniq only removes neighboring duplicates. If duplicates are scattered, sort first: sort file | uniq.

🔐 Hashes

A hash is a fingerprint. Change one letter in the file, and the fingerprint changes.

md5sum passwdfile > hashpasswd sha256sum passwdfile sha512sum passwdfile

📁 File management

mkdir creates folders. cp copies. mv moves or renames. rm deletes. There is no recycle bin in a normal shell.

mkdir -p test3/test4/test5 cp -p testfile1 /tmp/ mv oldname newname rm -rf test2 file testfile.txt

Archive, Search, Edit, Protect

This TP connects four survival skills: packing files, finding text, editing safely, and controlling access.

🧳 Archives and compression

tar makes a suitcase. gzip, bzip2, and xz squeeze the suitcase smaller.

NeedCommand
Create tartar -cvf file.tar testfile1 testfile2
List tartar -tvf file.tar
Extract tartar -xvf file.tar
gzip tartar -czvf file.tar.gz files...
bzip2 tartar -cvjf file.tar.bz2 files...
xz tartar -cvJf file.tar.xz files...
cpio createfind . | cpio -o > content.cpio
cpio extractcpio -idvu < content.cpio

🔍 Regex with grep

Regex is a fishing net for text. Different shapes catch different fish.

grep -i '^this' regex.txt grep -i 'example$' regex.txt grep -i 'example\.' regex.txt grep -E 'wonderful|wonderwomen' regex.txt grep -F 'wonder(full|women)' regex.txt

✍️ Vim basics

Vim has modes. Normal mode is for commands. Insert mode is for writing text. If you mix them up, Vim feels hostile because you are speaking the wrong language.

i # insert mode Esc # normal mode dd # delete line yy / p # copy / paste :wq # save and quit :q! # quit without saving

🛡️ Ownership and permissions

A file has an owner, a group, and others. Each can read r, write w, or execute/search x.

NeedCommandMeaning
Create usersudo useradd -m -d /home/newuser newuserCreate account and home.
Change ownersudo chown newuser filerightsGive the file to a user.
Change groupsudo chgrp newuser filerightsPut the file in a group.
Read/write for allchmod 666 filerightsEveryone can read and write.
Sticky bitchmod o+t testdirOnly owner/root deletes inside.
Setuidchmod u+s setuidfileRun with file owner's privileges.
Setgidchmod g+s testdirNew files inherit directory group.
Default maskumask 0026Subtract permissions from new files.
Permission trap Capital S or T means the special bit is set but execute/search permission is missing. That is usually a warning sign, not a feature.

Processes Are Little Workers

A process is a running program. Signals are messages you send to workers: stop, continue, terminate, or die now.

🏃 Monitor and signal processes

NeedCommandKid version
All processesps -efClass photo of all workers.
Live dashboardtopWatch workers in real time.
Memoryfree -hHow much desk space is free?
Find bash PIDspgrep -l bashFind workers by name.
List signalskill -lList all messages you can send.
Gentle stopkill -15 PIDPlease clean up and stop.
Forced stopkill -9 PIDStop now, no goodbye.
Pause/resumekill -19 PID / kill -18 PIDFreeze / continue.
By exact namepkill -x -15 nginxSignal all matching workers.
Nginx master vs worker Killing the master usually ends the workers. Killing a worker often makes the master create a replacement. That is not a contradiction; it is supervision.

🧵 Jobs, screen, tmux

Ctrl+Z pauses a foreground job. fg brings it back. bg lets it continue behind you. screen and tmux keep terminal sessions alive.

sleep 1000 Ctrl+Z fg bg jobs nohup sleep 500 & tmux

⚖️ Priority

nice starts a command with a priority. renice changes priority after the process is already running.

nice -n 5 sleep 1000 & ps -u $(whoami) -o pid,ni,cmd renice -n 10 -p PID renice -n 1 -u $(whoami)

🔗 Hard links vs symbolic links

Hard link

Two names point to the same inode. Change one, the other changes because they are the same data.

ln filelink1 filelink2

Symbolic link

A shortcut containing a path. If the target disappears, the link becomes broken.

ln -s filelink3 filelink4

📦 Containers with LXD

A virtual machine is a whole pretend computer. A container is a small separated room sharing the host kernel. LXD containers are lighter, but they are still Linux-on-Linux isolation, not full hardware emulation.

sudo apt install lxd-installer lxc list lxc image list lxc launch ubuntu:20.04 mycontainer lxc exec mycontainer -- /bin/bash

Storage: Toy Boxes, Labels, and Shelves

A disk is raw space. A partition cuts it. A filesystem organizes it. A mount attaches it to the house.

🧱 Storage stack

Disk: /dev/sdb Partition: /dev/sdb1 Filesystem: ext4 / xfs / btrfs Mount point: /home/user/xfs
  1. See disks.
    lsblk, cat /proc/partitions, fdisk -l.
  2. Create partitions.
    Use fdisk, gdisk, or parted.
  3. Make a filesystem.
    mkfs.ext4 /dev/sdb1, mkfs.xfs /dev/sdd1.
  4. Attach it.
    mount /dev/sdc1 ~/xfs, then use /etc/fstab for boot-time mounting.

🧰 Storage commands

NeedCommandMeaning
Block deviceslsblk, lsblk -fShow disks, partitions, filesystems.
Mounted usagedf -h, df -iShow space and inode usage.
UUIDsblkidShow stable device identifiers.
Check ext FSfsck /dev/sdd1Repair unmounted ext filesystem.
Swapmkswap, swapon, swapon --showUse disk space as emergency memory.
Disk usagedu -hs /usrMeasure folder size.
Raw copydd if=testfile of=testfile.123 bs=4096Copy bytes carefully.
ext tuningtune2fs -l /dev/sdaXRead or change ext filesystem settings.

📚 Filesystem personalities

ext2 old, no journal. ext3 adds journal. ext4 modern default. xfs strong for large data. btrfs snapshots/checksums. vfat removable Windows-friendly media.

🧪 XFS tools

XFS has its own repair and inspection tools. Use the right doctor for the right patient.

xfs_repair -n /dev/sdc1 xfs_repair -v /dev/sdc1 xfs_db /dev/sdc1 xfs_fsr /dev/sdc1

🧮 LVM in one picture

LVM lets you combine physical disks into flexible storage pools, then create logical volumes that can grow more easily.

Physical Volumes -> Volume Group -> Logical Volumes /dev/sdb1 vg_data lv_home /dev/sdc1 lv_logs
LayerCommandQuestion answered
PVpvsWhich physical disks are used?
VGvgsHow big is the shared pool?
LVlvsWhich virtual partitions exist?

Bad Ideas to Stop Believing

This is the part where I do not sugarcoat it. These mistakes lose points because the logic is wrong, not because the command spelling is ugly.

1. "sudo fixes everything" No. It only gives power. If your target is wrong, sudo makes the wrong action more dangerous.
2. "kill -9 is normal" False. Use SIGTERM first. SIGKILL is the hammer when cleanup does not matter or cannot happen.
3. "A symlink is another copy" False. It is a path shortcut. Delete the target, and the symlink points to nothing.
4. "uniq removes all duplicates" False unless duplicates are adjacent. Sort first for scattered duplicates.
5. "ext2 with journal is still ext2" Practically no: adding a journal with tune2fs -j moves it toward ext3 behavior.
6. "dpkg handles dependencies like apt" False. dpkg is lower-level; apt resolves dependency packages.
7. "A mounted filesystem can always be repaired" Dangerous. Many repair tools expect the filesystem to be unmounted.
8. "PATH means Linux searches everywhere" False. It searches only directories listed in PATH.

🧭 Command chooser

pwd

Show current directory.

ls -la

List files with details, including hidden ones.

man

Read command documentation.

systemctl

Manage services and targets.

journalctl -k

Read kernel logs from the journal.

apt install

Install packages with dependency solving.

sed

Edit text streams or files.

grep -E

Search text with extended regex.

ps -ef

List running processes.

kill -15 PID

Ask a process to terminate cleanly.

lsblk -f

Show disks, partitions, and filesystems.

mount

Attach a filesystem to the directory tree.

pvs / vgs / lvs

Inspect LVM layers.

ln / ln -s

Create hard or symbolic links.

tar

Create, list, and extract archives.

The One-Page Revision Checklist

If you can explain these out loud without hiding behind memorized commands, you are actually ready.

✅ What every TP taught

TPMain lessonMust-know commands
TP1Navigate, read docs, understand FHS.pwd, man, ls, cd
TP2Boot chain and service manager.systemctl, journalctl, shutdown
TP3Kernel modules, devices, libraries.uname, lsmod, modinfo, lspci, ldd
TP4Install and remove packages.dpkg, apt, apt-cache, yum, zypper
TP5Shell variables, finding files, streams.env, set, find, locate, tee, xargs
TP6Text filters and file management.head, tail, sort, tr, cut, sed, rm
TP7Archives, regex, Vim, permissions.tar, gzip, grep, vim, chmod, chown
TP8Processes, jobs, links, containers.ps, top, kill, jobs, ln, lxc
TP9Disks, filesystems, swap, LVM.lsblk, fdisk, mkfs, mount, df, pvs

📌 Source files used

This website is based on all workspace references: TP1 to TP9 subject PDFs, TP1 to TP5 answer PDFs, and TP6 to TP9 answer text files.

tp1 énoncé.pdf tp1 réponses.pdf tp2 énoncé.pdf tp2 réponses.pdf tp3 énoncé.pdf tp3 réponses.pdf tp4 énoncé.pdf tp4 réponses.pdf tp5 énoncé.pdf tp5 réponses.pdf tp6 énoncé.pdf tp6 réponses.txt tp7 énoncé.pdf tp7 réponses.txt tp8 énoncé.pdf tp8 réponses.txt tp9 énoncé.pdf tp9 réponses.txt
Final idea Linux is a system of names and relationships: files have paths, processes have PIDs, services have units, disks have partitions, filesystems have mount points, and users have permissions. Learn the relationships, then the commands become obvious.