Linux Essentials
Build a dependable Linux foundation by inspecting before changing, keeping commands reversible, and verifying results.
Before you start
Who is this for?
For IT learners who want to administer a Linux VM or server safely from the command line.
Prerequisites
- Basic computer use
- A disposable Linux VM or authorised test system
What you'll be able to do
- Navigate and manage files
- Use pipes and redirection
- Inspect processes and logs
- Install packages safely
- Reason about permissions
- Test networking and SSH
Practical outcome
You can build a small backup script and document its permissions, restoration, and failure behaviour.
1. Linux and distributions
Section titled “1. Linux and distributions”Linux technically refers to the kernel. A distribution combines it with user-space tools, a package system, installers, defaults, and a release policy. Debian/Ubuntu, Fedora/RHEL, openSUSE/SUSE, and Arch differ in package commands and support models. Use a disposable VM for experiments and read a command before running it, especially when it uses sudo, writes files, or acts recursively.
2. How a shell command works
Section titled “2. How a shell command works”The shell parses arguments, expands variables and wildcards, and starts a builtin or external program. Linux filenames and commands are case-sensitive:
name="Ada Lovelace"printf 'Hello, %s\n' "$name"command -v bashman lsls --helpQuotes protect spaces and prevent unintended expansion. A command’s exit status is available in $?; zero conventionally means success.
3. Navigate and inspect the filesystem
Section titled “3. Navigate and inspect the filesystem”The filesystem starts at /. Common paths include /home for user data, /etc for system configuration, /var for changing data and logs, /tmp for temporary files, /usr for installed programs, /dev for devices, and /proc//sys for kernel and device views.
pwdls -lacd /var/logfind . -maxdepth 2 -type f -name '*.log'Absolute paths start at /; relative paths start in the current directory. Hidden names begin with . but are not automatically protected.
4. Manage files safely
Section titled “4. Manage files safely”mkdir -p ~/bytepath-lab/inputprintf 'sample\n' > ~/bytepath-lab/input/example.txtcp --preserve=mode ~/bytepath-lab/input/example.txt ~/bytepath-lab/mv ~/bytepath-lab/example.txt ~/bytepath-lab/archive.txtInspect a wildcard before deleting. rm has no automatic recycle bin, and rm -r is irreversible. Prefer a disposable lab and explicit paths.
5. Streams, pipes, and search
Section titled “5. Streams, pipes, and search”Programs have standard input, standard output, and standard error. Redirect and combine small tools:
printf '%s\n' *.txt | sort | tee file-list.txtgrep -R --line-number 'timeout' ~/bytepath-labcommand 2>errors.log> overwrites, >> appends, and 2> redirects standard error. Use awk, cut, sort, and uniq only after confirming the input format.
6. Archives and backups
Section titled “6. Archives and backups”An archive groups files; compression reduces size. Inspect before extracting:
tar -czf ~/bytepath-lab/backup.tgz -C ~/bytepath-lab inputtar -tzf ~/bytepath-lab/backup.tgztar -xzf ~/bytepath-lab/backup.tgz -C ~/bytepath-lab/restoreA backup is trustworthy only after a restore test and an integrity check. Do not extract an unknown archive into a sensitive directory.
7. Processes, services, and logs
Section titled “7. Processes, services, and logs”ps aux --sort=-%mem | headpgrep -a sshfree -hdf -hsystemctl status sshjournalctl -u ssh --since '15 minutes ago'kill sends SIGTERM by default and gives a process a chance to stop cleanly. Use SIGKILL only as a last resort. Service names differ by distribution; inspect before changing them.
8. Packages and updates
Section titled “8. Packages and updates”Use the distribution’s trusted repositories and understand the change before confirming it:
# Debian/Ubuntuapt search package-namesudo apt install package-name# Fedora/RHELdnf search package-namesudo dnf install package-nameDo not mix repositories casually. Verify package origin, signatures, and update policy for third-party software.
9. Users, groups, and permissions
Section titled “9. Users, groups, and permissions”idgetent passwd "$USER"groupsls -l filechmod 640 fileNormal work should use an unprivileged account. sudo grants elevated rights for a specific command and should be used with a reason. For deeper mode, ACL, and special-bit practice, continue to Linux Permissions.
10. A safe Bash script
Section titled “10. A safe Bash script”#!/usr/bin/env bashset -euo pipefail
source_dir=${1:?usage: $0 SOURCE_DIR DESTINATION}destination=${2:?usage: $0 SOURCE_DIR DESTINATION}mkdir -p "$destination"tar -czf "$destination/backup-$(date +%F).tgz" -C "$source_dir" .printf 'Created backup in %s\n' "$destination"set -euo pipefail makes several classes of mistakes visible, but it is not a substitute for testing. Quote variables, validate inputs, and use a temporary directory for experiments.
11. Networking and SSH
Section titled “11. Networking and SSH”Begin with state, then test one dependency at a time:
ip addressip routess -lntupgetent hosts example.testcurl --verbose https://example.test/A successful ping, DNS lookup, TCP connection, and HTTP response test different layers. SSH is an encrypted remote shell; connect only to authorised systems:
ssh user@192.0.2.10Verify the host-key fingerprint through a trusted channel on first connection. Protect private keys with restrictive permissions and never commit them.
Practical project: backup and restore
Section titled “Practical project: backup and restore”- Create
~/linux-lab/input,archive, andrestore. - Add three harmless text files and search them with
grep. - Write or adapt a script that creates a dated
tar.gz. - Set the archive to
640and verify owner and group. - List the archive before extracting it.
- Restore it and compare contents with
diff -r. - Document what happens when the input path does not exist.
What you should be able to do now
Section titled “What you should be able to do now”You should be able to inspect a Linux system, make a controlled change, verify it, and explain the evidence. Continue with Linux Permissions or use the backup and restore lab.
Related: Bash Scripting, Linux Services and systemd Logs, and SSH and Server Hardening.