CertPrep
Back to Resources

LPIC-1 and LPIC-2 Command Cheat Sheet

July 13, 2026~15 min read

This cheat sheet covers essential Linux commands for the LPIC-1 and LPIC-2 exams, organized by domain. Use it as a quick reference during study and lab practice.

System Architecture

CommandDescriptionCommon FlagsExample
uname -aShow all system information-r (kernel release), -m (architecture)uname -r6.1.0-16-amd64
lscpuDisplay CPU architecture infolscpu | grep "Model name"
lsblkList block devices-f (filesystem), -m (permissions)lsblk -f
dmidecodeRead hardware info from BIOS-t processor, -t memorydmidecode -t memory
lspciList PCI devices-v (verbose), -nn (numeric IDs)lspci -nn | grep VGA
lsusbList USB devices-v (verbose), -t (tree)lsusb -t
lsmodList loaded kernel moduleslsmod | grep ^usb
modinfoShow module information-p (parameters), -d (description)modinfo -p e1000

Boot Process and GRUB

CommandDescriptionCommon FlagsExample
grub-installInstall GRUB to disk--target=x86_64-efi, --boot-directorygrub-install --target=x86_64-efi /dev/sda
grub-mkconfigGenerate GRUB config-o /boot/grub/grub.cfggrub-mkconfig -o /boot/grub/grub.cfg
update-grubDebian shortcut for grub-mkconfigupdate-grub
dmesgPrint kernel ring buffer-T (human timestamps), -w (follow)dmesg -T | grep error
journalctl -xbView boot logs (systemd)-b -1 (previous boot), -p err (errors)journalctl -b -p err
systemd-analyze blameShow boot time per servicesystemd-analyze blame | head -10

Package Management (Debian/Ubuntu)

CommandDescriptionCommon FlagsExample
apt-get updateRefresh package indexapt-get update
apt-get installInstall package with deps--no-install-recommends, -yapt-get install -y nginx
apt-get removeRemove package--purge (remove config)apt-get remove --purge apache2
apt-get upgradeUpgrade all packages--dry-run (simulate)apt-get upgrade --dry-run
dpkg -iInstall .deb packagedpkg -i package.deb
dpkg -rRemove installed package-P (purge)dpkg -r nginx
dpkg -lList installed packagesdpkg -l | grep nginx
dpkg -LList files in a packagedpkg -L nginx-common
dpkg --configure -aFix partly-installed packagesdpkg --configure -a
apt-cache searchSearch package databaseapt-cache search web server
apt-cache policyShow package version infoapt-cache policy nginx

Package Management (RHEL/Fedora)

CommandDescriptionCommon FlagsExample
dnf installInstall package-ydnf install -y nginx
dnf removeRemove packagednf remove nginx
dnf updateUpdate all packagesdnf update
dnf searchSearch packagesdnf search web server
dnf groupinstallInstall a group of packagesdnf groupinstall "Web Server"
rpm -ivhInstall RPM package-U (upgrade), -e (erase)rpm -ivh package.rpm
rpm -qaQuery all installed RPMs-qi (info), -ql (file list)rpm -qa | grep nginx
rpm -VVerify installed packagerpm -V nginx

GNU and Unix Commands

CommandDescriptionCommon FlagsExample
grepSearch lines matching pattern-r (recursive), -i (case), -v (invert), -E (extended regex)grep -ri "error" /var/log/
sedStream editor for text transform-i (in-place), s/old/new/g (substitute)sed -i 's/foo/bar/g' file.txt
awkPattern scanning and processing-F (field separator)awk '{print $1, $3}' file.txt
findSearch for files-name, -type, -mtime, -execfind /var -name "*.log" -mtime +7
sortSort lines of text-u (unique), -n (numeric), -r (reverse)sort -u file.txt
wcWord/line/byte count-l (lines), -w (words)wc -l /var/log/syslog
cutExtract fields from lines-d (delimiter), -f (fields)cut -d: -f1 /etc/passwd
trTranslate/delete characters-d (delete), -s (squeeze)tr '[:upper:]' '[:lower:]' < file
teeRead stdin and write to file + stdout-a (append)echo "text" | tee -a file.log
xargsBuild and execute command lines-n (max args), -I (replace str)find . -name "*.tmp" | xargs rm
tarArchive utility-c (create), -x (extract), -z (gzip), -f (file), -v (verbose)tar -czvf archive.tar.gz /path/
gzip/gunzipCompress/decompress files-k (keep original), -v (verbose)gzip -k file.txt
bzip2Block-sorting file compressor-k, -z, -dbzip2 -z file.txt
xzLZMA2 compressor (highest ratio)-z, -d, -kxz -z file.tar

Filesystems and Storage

CommandDescriptionCommon FlagsExample
mountMount a filesystem-t (type), -o (options)mount -t ext4 /dev/sdb1 /mnt
umountUnmount a filesystem-l (lazy), -f (force)umount -l /mnt
df -hShow disk usage (human-readable)-T (type), -i (inodes)df -hT
du -shShow directory size-a (all), --max-depth=Ndu -sh /var/log/
fsckCheck/repair filesystem-f (force), -y (auto-yes)fsck -f /dev/sdb1
mkfs.ext4Create ext4 filesystem-L (label), -m (reserved blocks %)mkfs.ext4 -L data /dev/sdb1
e2labelShow/change ext labele2label /dev/sdb1 mydata
tune2fsAdjust ext filesystem params-l (list), -c (max mount count)tune2fs -l /dev/sdb1
blkidShow block device attributesblkid /dev/sdb1
partedPartition disk (GPT)mklabel gpt, mkpartparted /dev/sdb mklabel gpt
fdiskPartition disk (MBR)-l (list)fdisk -l

LVM (Logical Volume Manager)

CommandDescriptionExample
pvcreate /dev/sdb1Create a physical volumepvcreate /dev/sdb1 /dev/sdc1
pvsList physical volumespvs
pvdisplayShow detailed PV infopvdisplay /dev/sdb1
vgcreate vg_data /dev/sdb1Create a volume groupvgcreate vg_data /dev/sdb1 /dev/sdc1
vgsList volume groupsvgs
vgdisplayShow detailed VG infovgdisplay vg_data
vgextend vg_data /dev/sdd1Add PV to VGvgextend vg_data /dev/sdd1
lvcreate -L 50G -n lv_data vg_dataCreate a logical volumelvcreate -L 50G -n lv_data vg_data
lvcreate -l 100%FREE -n lv_data vg_dataUse all remaining free spacelvcreate -l 100%FREE -n lv_root vg_system
lvsList logical volumeslvs
lvextend -L +10G /dev/vg_data/lv_dataExtend LV by 10Glvextend -L +10G /dev/vg_data/lv_data
lvreduce -L -5G /dev/vg_data/lv_dataReduce LV by 5Glvreduce -L -5G /dev/vg_data/lv_data

After extending an LV, resize the filesystem:

  • ext4: resize2fs /dev/vg_data/lv_data
  • XFS: xfs_growfs /mount/point

RAID (mdadm)

CommandDescriptionExample
mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd[bcd]1Create RAID 5mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm --detail /dev/md0Show detailed RAID infomdadm --detail /dev/md0
mdadm --manage /dev/md0 --add /dev/sde1Add disk to arraymdadm --manage /dev/md0 --add /dev/sde1
mdadm --manage /dev/md0 --fail /dev/sdb1Fail a diskmdadm --manage /dev/md0 --fail /dev/sdb1
mdadm --manage /dev/md0 --remove /dev/sdb1Remove a diskmdadm --manage /dev/md0 --remove /dev/sdb1
cat /proc/mdstatCheck RAID statuscat /proc/mdstat

Shell Scripting

ConceptSyntaxExample
Shebang#!/bin/bash#!/bin/bash
VariableVAR=valueNAME="John"
Variable use$VAR or ${VAR}echo "Hello, $NAME"
Command substitution$(cmd) or `cmd`DATE=$(date +%Y-%m-%d)
Arithmetic$((expr))TOTAL=$((COUNT + 1))
If statementif [ cond ]; then ... fiif [ "$NAME" = "root" ]; then echo "admin"; fi
For loopfor i in LIST; do ... donefor file in *.txt; do echo "$file"; done
While loopwhile [ cond ]; do ... donewhile read line; do echo "$line"; done < file
Case statementcase $VAR in pattern) ...;; esaccase $OPT in -h) usage;; *) error;; esac
Functionfunc() { ... }usage() { echo "Usage: $0 [-h]"; }
Exit status$?cmd; if [ $? -eq 0 ]; then echo OK; fi
Test operators-f (file), -d (dir), -z (empty), -n (non-empty)[ -f /etc/passwd ] && echo exists

User and Group Management

CommandDescriptionCommon FlagsExample
useraddCreate user-m (home), -s (shell), -G (groups)useradd -m -s /bin/bash -G sudo jdoe
usermodModify user-aG (append groups), -L (lock), -U (unlock)usermod -aG docker jdoe
userdelDelete user-r (remove home + mail)userdel -r jdoe
groupaddCreate group-g (GID)groupadd -g 1001 developers
groupdelDelete groupgroupdel developers
passwdChange password-l (lock), -u (unlock), -d (delete)passwd jdoe
chageChange password aging-l (list), -d (last day), -E (expire)chage -d 0 jdoe
idShow user identityid jdoe
whoShow logged-in users-a (all details)who -a
wShow who is logged in + activityw
lastShow last logins-n 10 (limit)last -n 10

Process Management

CommandDescriptionCommon FlagsExample
ps auxList all processes-ef (full), --forest (tree)ps aux --sort=-%mem | head -10
topInteractive process viewer-u user, -p PIDtop -u www-data
htopEnhanced process viewer (if installed)htop
kill PIDSend SIGTERM to process-9 (SIGKILL), -15 (SIGTERM), -1 (SIGHUP)kill -9 1234
killallKill by process name-9, -15, -I (case-insensitive)killall -9 nginx
pkillKill by name or pattern-u user, -f (full command)pkill -u jdoe -f "node app"
pgrepList PID by name-u, -l (show name)pgrep -l nginx
niceStart with priority-n (nice value, -20 to 19)nice -n 10 backup.sh
reniceChange priority-n (priority), -p (PID)renice -n 5 -p 1234
nohupRun immune to hangupsnohup backup.sh &
bg/fgBackground/foreground jobsCtrl+Z, then bg
jobsList background jobs-l (with PIDs)jobs -l

Networking

CommandDescriptionCommon FlagsExample
ip addrShow/manipulate network interfacesadd, delip addr show eth0
ip linkManage network interfacesset up, set downip link set eth0 up
ip routeShow/manage routing tableadd, delip route add default via 10.0.0.1
ip neighShow ARP cacheip neigh
ss -tlnpList TCP listening sockets-u (UDP), -a (all), -s (stats)ss -tlnp | grep :80
pingTest network reachability-c (count), -i (interval)ping -c 4 google.com
tracerouteTrace route to host-n (numeric), -w (wait)traceroute -n google.com
nc (netcat)TCP/UDP swiss army knife-l (listen), -z (scan), -v (verbose)nc -zv 10.0.0.1 22-443
nmapNetwork exploration-sS (SYN scan), -sn (ping sweep)nmap -sn 10.0.0.0/24
digDNS lookup tool+short, -x (reverse)dig +short example.com
nslookupLegacy DNS lookupnslookup example.com
hostSimplified DNS lookuphost example.com
curlHTTP/HTTPS client-I (headers), -v (verbose)curl -I https://example.com
wgetFile download utility-O (output), -q (quiet)wget -O file.zip https://url/file.zip

System Security

CommandDescriptionExample
chmod 755 fileChange file permissions (rwxr-xr-x)chmod 750 /root
chown user:group fileChange file owner/groupchown -R jdoe:www-data /var/www
setfacl -m u:jdoe:rw fileSet ACL entrysetfacl -m g:developers:rx /project
getfacl fileView ACLsgetfacl /etc/shadow
chattr +i fileSet immutable flagchattr +i /etc/hosts
lsattr fileList file attributeslsattr /etc/hosts
iptables -LList iptables rulesiptables -A INPUT -p tcp --dport 22 -j ACCEPT
nft list rulesetList nftables rulesnft add rule inet filter input tcp dport 443 accept
getenforceGet SELinux modesetenforce 1 (enforcing)
sestatusSELinux statussestatus | grep ^SELinux
ls -ZShow SELinux contextps -eZ | grep httpd
restorecon -Rv /pathRestore default SELinux contextsrestorecon -Rv /var/www
setsebool -P httpd_can_network_connect onSet SELinux booleansetsebool -P httpd_can_sendmail on
sealert -a /var/log/audit/audit.logAnalyze SELinux denialssealert -a /var/log/audit/audit.log
openssl enc -aes-256-cbc -salt -in file -out file.encEncrypt fileopenssl enc -d -aes-256-cbc -in file.enc -out file
gpg --symmetric --cipher AES256 fileGPG symmetric encryptiongpg --decrypt file.gpg
ssh-keygen -t ed25519Generate SSH keyssh-keygen -t rsa -b 4096
ssh-copy-id user@hostCopy SSH key to hostssh-copy-id -i ~/.ssh/id_ed25519 user@host

System Monitoring

CommandDescriptionExample
free -hShow memory usagefree -h
vmstat 2 10Virtual memory stats (every 2s, 10 times)vmstat -s (summary)
iostat -x 2I/O stats (extended, every 2s)iostat -x | grep sda
mpstat -P ALL 2Per-CPU usage (every 2s)mpstat -P ALL
sar -u 2 10CPU stats (every 2s, 10 times)sar -r (memory), sar -b (I/O)
uptimeShow system uptime and loaduptime
lsofList open fileslsof -i :80, lsof -u jdoe
fuser -v /pathShow processes using file/socketfuser 80/tcp

Test Your Knowledge with Practice Exams

Ready to put this knowledge to the test? Our LPI practice portal includes 200+ realistic questions covering LPIC-1, LPIC-2, LPIC-3, and DevOps Tools Engineer certifications. Study mode, timed exams, domain breakdowns, and weak-area analysis included.

Start Free Preview →

Related Articles

Ready to Test Your Knowledge?

Try our practice exams with hundreds of realistic questions.

Start Practicing →