LPI Linux Essentials study materials
LPI Linux Essentials study resources

LPI Linux Essentials cheat sheet

LPI Linux Essentials · Keep the key ideas within reach.

Quick reference

The Linux Operating System and Open Source Software

  • The four freedoms of free software (FSF): run the program for any purpose, study and change it, redistribute copies, and distribute modified versions; access to source code is a precondition for freedoms 1 and 3.

  • Open source is a development methodology defined by the OSI's ten criteria; free software is a philosophical/legal stance defined by the FSF's four freedoms. A license can satisfy one without the other.

  • GPLv2 requires derivative works distributed to others be licensed under the GPL; GPLv3 adds patent grants, anti-tivoization terms, and compatibility with Apache 2.0. LGPL permits linking from proprietary code under conditions.

  • Permissive licenses (MIT, BSD-2/3, Apache 2.0) allow relicensing under proprietary terms; Apache 2.0 adds an express patent grant and requires NOTICE-file retention.

  • The kernel is the program that mediates hardware access; user space programs request kernel services via system calls. The shell is an ordinary user-space program, not part of the kernel.

  • A distribution = kernel + libraries (glibc) + package manager + userland tools + default configuration. Package formats: deb (Debian/Ubuntu, dpkg/apt) and rpm (RHEL/Fedora/SUSE, rpm/dnf/zypper).

  • Filesystem Hierarchy Standard: /etc holds host-specific configuration, /var holds variable data (logs, spool, databases), /usr holds the read-only userland, /home holds user home directories, /tmp is world-writable scratch space.

  • The boot sequence is firmware → bootloader (GRUB) → kernel + initramfs → init (systemd PID 1) → targets/units. systemd units are enabled by symlinks in target directories, not by editing scripts.

Quick reference

Command Line Basics

  • Quoting rules: single quotes preserve everything literally; double quotes still expand $variables, backticks and \ escapes; backslash escapes the next single character.

  • Redirection: > truncates and writes, >> appends, 2> redirects stderr, &> merges stdout and stderr, < feeds stdin. A pipe | connects stdout of the left command to stdin of the right.

  • Exit status 0 means success; any nonzero value means failure. $? holds the status of the last foreground command.

  • Globs are expanded by the shell before the command runs: * matches any string, ? matches one character, [abc] matches a set. Globs do not match a leading dot and are not regular expressions.

  • File inspection: ls -l shows mode, links, owner, group, size, mtime; file reports content type by magic bytes; stat shows inode metadata; less pages text without loading it all.

  • Finding things: find searches the live filesystem by name/type/size/mtime and can execute commands; locate queries a prebuilt database (updatedb); grep searches file contents by pattern.

  • Permissions in symbolic form: u/g/o (user, group, other) and r/w/x; chmod u+x adds execute, chmod g-w removes group write, chmod o=r sets other to read only.

  • Absolute paths start at /; relative paths start at the current directory. . is the current directory, .. is its parent, ~ is the current user's home, - is the previous directory for cd.

Quick reference

Data Processing

  • stdin/stdout/stderr are file descriptors 0, 1 and 2. Filters read stdin, write stdout, and can be chained with pipes to build processing pipelines.

  • grep options: -i case-insensitive, -v invert match, -c count matching lines, -n show line numbers, -r recursive, -E extended regex, -F fixed strings.

  • sed 's/old/new/' replaces the first match per line; the g flag replaces all matches; -i edits in place; -n with p prints only matched lines.

  • awk splits each record into fields $1..$NF using FS (default whitespace); NR is the record number, NF the field count; patterns select records and actions run per record.

  • cut extracts columns by delimiter (-d) and field list (-f), or character positions (-c); it cannot reorder or re-split on multiple delimiters flexibly, unlike awk.

  • sort sorts lines (-n numeric, -r reverse, -k field, -t delimiter, -u unique); uniq removes adjacent duplicates only, so input must be sorted first; uniq -c prefixes counts.

  • head -n N and tail -n N show the first or last N lines; tail -f follows a growing file; wc -l counts lines, -w words, -c bytes.

  • Regular expression anchors: ^ start of line, $ end of line, . any single character, * zero or more of the preceding, [ ] character class, | alternation in basic regex.

Quick reference

Linux System Administration Basics

  • The root account has UID 0 and bypasses permission checks. Use sudo to run single commands with elevated privilege rather than logging in as root.

  • Users are defined in /etc/passwd (name:x:UID:GID:comment:home:shell); password hashes live in /etc/shadow, readable only by root. Groups are in /etc/group.

  • useradd creates an account, usermod modifies it (-aG appends supplementary groups, -L locks), userdel -r removes the home directory; passwd sets or changes passwords.

  • Process control: ps shows a snapshot, top is interactive, kill sends a signal by PID, killall matches by name. SIGTERM (15) requests termination; SIGKILL (9) cannot be caught or ignored.

  • systemctl start/stop/restart/status/enable/disable manages systemd units; journalctl -u reads that unit's logs; systemctl --failed lists failed units.

  • Package management: apt update refreshes metadata while apt upgrade installs newer versions; dpkg -i installs a local .deb; dnf install/remove and rpm -qa query RPM systems.

  • Disk and filesystem tools: df reports free space per filesystem, du -sh summarizes directory usage, lsblk lists block devices, mount attaches a filesystem to a directory.

  • Scheduling: cron entries in /etc/crontab have five time fields (minute hour day month weekday) plus user and command; systemd timers are the modern equivalent and are enabled as units.

Quick reference

Security and File System Permissions

  • chmod numeric mode: read=4, write=2, execute=1, summed per triad (owner, group, other). 644 = rw-r--r--, 755 = rwxr-xr-x, 600 = rw-------.

  • Directories: read allows listing names, execute allows traversing/accessing entries, write allows creating and deleting entries. Without x, a directory cannot be entered even if readable.

  • umask is subtracted from the default base: files start at 666 and directories at 777. umask 022 yields 644 for files and 755 for directories.

  • Special bits: setuid (4000) runs a program as its owner, setgid (2000) runs with the file's group or makes a directory inherit its group, sticky (1000) on a directory restricts deletion to the file's owner.

  • chown changes owner (and group with owner:group); chgrp changes group only. Only root can change a file's owner; an owner can change the group to one they belong to.

  • Symbolic links store a path and carry no meaningful permissions of their own; access is governed by the target. Hard links share one inode and cannot span filesystems or link directories.

  • SSH key authentication uses a key pair: the public key is stored in ~/.ssh/authorized_keys on the server, the private key stays on the client and must be protected (chmod 600).

  • The root of trust is the superuser: file ownership is stored in the inode, so copying a file as root can change its effective owner. Never make a file world-writable (mode 777) to solve access problems.