Linux and the Command Line overview
114 topics in 15 lessons, each in one line. Every topic opens the page that teaches it.
After this course you can
- Work fluently in the shell: find, filter and change files and text, and read what a server is telling you.
- Administer a server: users and permissions, services, packages, disks and LVM, networking, firewalls and SSH.
- Automate with Bash and cron, and diagnose a sick server from the symptom, SELinux denials and failed boots included.
1What Linux is, and your first commands
- Linux and distributionsWhat is on the other end when you log in to a Linux server?
- Terminal and shellYour text goes to a shell, and the shell starts programs
- First commandsWhich commands are safe to type first on any machine?
- Command syntaxOne line: a program name, then options and arguments
- Manual pagesThe manual comes in numbered sections; ask for the right one
- LabGet a machine of your own and look around it
2Files and directories
- Moving aroundWhere am I, what is here, and how do I get somewhere else?
- PathsFrom the root, or from where you stand
- Filesystem hierarchyEvery file hangs from /, and each top folder has one job
- Copy, move, deleteHow do I make, copy, rename and delete without a mouse?
- InodesA name points to an inode, and the inode is the file
- Hard and symbolic linksA second name for the same inode, or a note with a path
- Finding filesWalk the tree and test every file: where, which, then what
- Archives and compressiontar bundles the files; the compressor trades time for size
- LabMap the mounts, make both links, find and archive
3Viewing and editing text
4Pipes and text tools
- Standard streamsThree numbered streams: input, results and errors
- RedirectionRewire the streams before the program starts, left to right
- PipesOne program’s output becomes the next one’s input, as both run
- grepOut of 8,000 lines, how do you see only the ones that matter?
- Text toolsSmall tools, one job each, joined by pipes
- PipelinesSix stations turn 2,000 log lines into one answer
- Regular expressionsDescribe the shape of a line, and grep finds every one
- sedEdit a stream line by line, without opening an editor
- awkSplit each line into fields, then act on the lines that match
- LabAnswer questions about a web log with nothing but pipes
5How the shell works
- Shell expansionThe line is rewritten, in a fixed order, before anything runs
- QuotingQuotes choose which of those rewrites happen
- VariablesHow do you name a value once and use it in many commands?
- Environment variablesExported variables are copied into every program you start
- Command search and PATHA bare name is searched for, and the first match wins
- Exit statusEvery command ends with a number, and 0 means success
- History and aliasesHow do experienced people type so little?
- LabAsk the shell what it will do before it does it
6Users, groups and permissions
- Permission deniedWhy can ana not read a file that is sitting right there?
- Users and groupsThe kernel knows you by numbers: a UID and your groups
- File permissionsNine bits: read, write and execute, for three kinds of user
- chmod, chgrp, chownHow do you change who may do what?
- Permission checksExactly one of the three sets applies, checked in order
- Directory permissionsOn a folder, write means you may delete what is inside
- sudoOne command as root, if a rule allows it, and on the record
- Account managementCreate, group, age and remove an account in five commands
- LabBuild a team folder and prove who can reach it
7Processes
- Programs and processesWhat exactly is running when a program runs?
- top and psThe header is the machine; each row is a process
- ProcessesEvery process has a parent, back to PID 1
- SignalsAsk a process to stop before you force it
- Job controlOne job has the terminal; the others wait or run behind
- Load averageRead the load against the number of CPUs
- LabStart, inspect, reprioritise and end processes
8Services and start-up
- ServicesWhat keeps a web server running when nobody is logged in?
- Starting and enablingstart is for now; enable is for every boot after
- Service statusEnabled, running, and what it last said, in one screen
- The journalOne indexed log for everything, filtered in an instant
- Service unitsA short text file turns a program into a managed service
- Boot processFirmware, bootloader, kernel, initramfs, then systemd
- Scheduled jobsTimers, cron lines and at jobs: three ways to run later
- LabWrite a service that survives a crash and a reboot
9Installing software
- PackagesFiles, plus a record of what they need and where they went
- RepositoriesA signed index the package manager trusts
- DependenciesAsk for one package, receive the tree it needs
- apt and dnfTwo families of tools, the same ten verbs
- UpdatesPatch on a schedule, and keep the last kernel
- LabInstall, trace and remove on both families
10Disks and file systems
- Block devicesA disk is cut into partitions, and file systems sit on them
- Adding storageFive steps from a raw disk to a mount that survives reboot
- fstabSix fields per line, and name the file system by UUID
- LVMPool the disks, then cut volumes from the pool
- Growing a volumeA full file system, fixed in one command while in use
- LabFrom a blank disk to a permanent, growing mount
11Networking
- Six questionsA server cannot be reached. What could be wrong?
- InterfacesEach network card has a name, a MAC address and IP addresses
- Subnets and routesLocal addresses are reached directly; the rest go to the gateway
- Name resolutionThe hosts file is read before DNS, and getent shows what programs see
- NetworkManagerChanges made with ip vanish; profiles saved with nmcli stay
- Socketsss shows who is listening, and on which address
- firewalldZones list what may come in, and only saved rules survive
- TroubleshootingTest from the bottom up and stop at the first failure
- LabA fixed address, a name and an open port
12SSH and remote work
- Logging inHow do you get a shell on a machine in another building?
- Known hostsTrust the server’s key once, and ssh checks it every time after
- Key pairsThe private key stays with you; the public key goes everywhere
- Client configOne config file turns long commands into short names
- Copying filesrsync sends only what changed; scp sends everything
- HardeningNo root, no passwords, and only the people you name
- LabKey login, file copies, a tunnel and a hardened server
13Shell scripts
- ScriptsA file of commands, with a first line naming its interpreter
- ExpansionBefore a line runs, bash fills in every $
- QuotingAn unquoted variable splits at spaces; quotes keep it whole
- Exit codes and testsif runs a command and acts on its exit status
- LoopsRepeat for each item, each line or each argument
- A real scriptA backup script, line by line
- Failing safelyMake the script stop at the first failure, and say where
- SchedulingFive fields say when; cron runs it with no one watching
- LabWrite, break and schedule a backup script
14Troubleshooting a server
- TriageSeven symptoms, the first command for each, and what it shows
- LogsOne journal, filtered by unit, priority, boot and time
- A service will not startA service will not start. Where do you look?
- Disk pressuredf finds the full disk, du the folder, lsof the hidden space
- Memory pressureRead "available", not "free", and watch for the OOM killer
- SELinuxEvery file and process has a label, and labels decide access
- Rescue and emergencyStop the boot early enough to repair what breaks it
- LabBreak it, then fix it from the symptom
15The disk filled up at 3 a.m.Worked case
- The problemA full disk breaks whatever needs to write next
- TriageNarrow it down: how full, then where, one level at a time
- The first fixDeleting the file removed its name, not its space
- The causeThe app still holds the deleted file open
- The fixEmpty the file the app still holds, then fix what made it grow
- PreventionRotate logs, cap the journal, and alert while there is time
- The runbookA full disk has a six-step runbook
- A real caseAt GitLab in 2017, the wrong host at night, and backups nobody had restored
Sources and credit
61 sourcesThe chapters and drawings are written by NeuroqAI from these sources. Each lesson lists its own at the end of its chapter, and figures on the pages are taken from them or computed from them.