LFCS study materials
LFCS study resources

LFCS cheat sheet

LFCS · Keep the key ideas within reach.

Quick reference

Operations Deployment

  • systemctl start UNIT activates a unit now; systemctl enable UNIT configures it to start at boot. Use systemctl enable --now UNIT to do both.

  • After editing or adding unit files under /etc/systemd/system, run systemctl daemon-reload before restarting the service.

  • journalctl -u UNIT -b shows one unit's messages from the current boot; persistent journals require the /var/log/journal directory.

  • Cron fields are minute, hour, day-of-month, month, day-of-week; /etc/crontab includes a user field before the command, user crontabs do not.

  • nice values run from -20 to 19; lower numbers receive more CPU priority. kill sends SIGTERM by default; SIGKILL (-9) cannot be caught or ignored.

  • systemctl get-default shows the boot target; systemctl set-default multi-user.target or graphical.target changes it.

  • Debian-family GRUB regeneration uses update-grub; RHEL-family uses grub2-mkconfig -o /boot/grub2/grub.cfg; kernel arguments commonly live in /etc/default/grub.

  • apt update refreshes package indexes; apt upgrade installs available updates; dnf install/remove manages RPM packages on RHEL-family systems.

Quick reference

Networking

  • ip addr show lists interface addresses; ip addr add CIDR dev IFACE adds one; ip link set dev IFACE up activates the link.

  • ip route show displays routes; the default route is 0.0.0.0/0 and can be added with ip route add default via GATEWAY.

  • ss -tulpn lists listening TCP and UDP sockets numerically with process owners; -t TCP, -u UDP, -l listening, -n numeric, -p process.

  • /etc/resolv.conf lists DNS nameservers; /etc/nsswitch.conf controls resolution order; getent hosts NAME tests the full NSS path.

  • firewall-cmd --add-service=http --permanent changes persistent firewalld config; firewall-cmd --reload applies it; without --permanent the rule is runtime-only.

  • NetworkManager connections are changed with nmcli connection modify NAME ... followed by nmcli connection up NAME.

  • hostnamectl set-hostname NAME sets the persistent hostname; /etc/hosts provides local name-to-address mappings.

  • nc -zv HOST PORT tests TCP reachability; curl -I fetches only HTTP headers; ping tests ICMP echo reachability.

Quick reference

Storage

  • lsblk shows the block-device tree; lsblk -f adds filesystem type, UUID, and label; blkid prints UUIDs and filesystem types.

  • /etc/fstab has six fields: device, mountpoint, fstype, options, dump, fsck pass; use UUID= because kernel device names can change.

  • mount DEVICE MOUNTPOINT attaches a filesystem; umount MOUNTPOINT detaches it; mount -a mounts all eligible fstab entries and tests fstab syntax.

  • mkfs.ext4 DEVICE creates an ext4 filesystem and destroys existing data on that device; mkfs.xfs DEVICE creates XFS.

  • LVM order: pvcreate DEVICE, vgcreate VG DEVICE, lvcreate -L SIZE -n LV VG; lvextend -r grows the logical volume and filesystem together.

  • df -h reports filesystem space; df -i reports inode usage; du -sh PATH summarizes space consumed by a file or directory tree.

  • Swap is initialized with mkswap DEVICE and activated with swapon DEVICE; add an fstab entry with sw to persist it.

  • mdadm --create /dev/md0 --level=1 --raid-devices=2 DEV1 DEV2 builds a mirror; /proc/mdstat shows array status.

Quick reference

Essential Commands

  • chmod numeric modes: 755 is rwxr-xr-x, 644 is rw-r--r--; chown USER:GROUP PATH changes ownership; chgrp changes group only.

  • umask removes permission bits from base modes: directories start at 777 and regular files at 666; umask 022 yields 755 directories and 644 files.

  • grep -r searches recursively; -i ignores case, -n prints line numbers, -v inverts matches, -E uses extended regular expressions, -l prints filenames only.

  • find PATH -name '*.conf' -type f -mtime -7 selects matching files modified in the last seven days; -exec CMD {} ; runs CMD per match.

  • tar -czf ARCHIVE PATH creates a gzip archive; tar -xzf ARCHIVE extracts; tar -tf ARCHIVE lists; -C DIR selects the extraction directory.

  • The operator > overwrites stdout, >> appends stdout, 2> redirects stderr, &> redirects both, and | pipes stdout to the next command; tee writes to a file and stdout.

  • ln TARGET LINK creates a hard link to the same inode; ln -s TARGET LINK creates a symbolic link; hard links cannot cross filesystems.

  • sed 's/old/new/g' replaces globally; awk '{print $1}' prints the first whitespace-separated field; sort -u sorts and removes duplicates; uniq -c counts adjacent duplicates.

Quick reference

Users and Groups

  • useradd -m -s /bin/bash -G GROUP USER creates a user with a home directory, login shell, and supplemental group; passwd USER sets the password.

  • usermod -aG GROUP USER appends a supplemental group; omitting -a replaces the user's supplemental group list.

  • /etc/passwd fields are name, password placeholder, UID, GID, GECOS, home, and shell; password hashes live in /etc/shadow; group membership is in /etc/group.

  • id USER shows UID, primary GID, and supplemental groups; getent passwd USER queries the NSS database; groups USER lists group names.

  • visudo edits /etc/sudoers safely; a rule like %group ALL=(ALL:ALL) ALL grants sudo privileges to all members of that group.

  • chage -l USER shows password aging; chage -M DAYS USER sets maximum password age; chage -E DATE sets account expiration.

  • su - USER starts a login shell and loads the target user's environment; su USER changes identity while generally preserving the current environment.

  • /etc/skel is copied into a new home directory when useradd -m creates it; files there provide default shell configuration.