CertGrid CertGrid

LPIC-1 command cheat sheet

The commands 101-500 and 102-500 ask for, grouped by LPI topic number and shown in both package families where the two differ. Every output is from a real session on this path's own two machines - one Debian-family, one RPM-family.

Topic 102 - Installation and package management

  • dpkg -l | grep -c '^ii'

    Count installed packages. The `ii` state field is what `dpkg -l` leads with, and it matters again when a package reaches `rc`.

    Full guide
  • rpm -qa | wc -l

    The same count on the RPM family. Do not compare the two numbers - RPM splits software into far more, smaller packages.

    Full guide
  • dpkg -S <file>

    Which package owns a file. Prints `package: path`.

    Full guide
  • rpm -qf <file>

    The same question on RPM. Prints the full name-version-release-architecture.

    Full guide
  • dpkg -L <pkg> / dpkg-query -W -f='${Conffiles}\n' <pkg>

    What a package contains, and which of those files are configuration. Debian records an md5 per conffile so it knows at upgrade time whether you edited it.

    Full guide
  • rpm -ql <pkg> / rpm -qc <pkg>

    The same pair on RPM. `-ql` lists files only - no directories, unlike `dpkg -L`.

    Full guide
  • dpkg -r <pkg>

    Remove but KEEP configuration. The package lands in state `rc`, which is what `dpkg -l | grep '^rc'` finds.

    Full guide
  • dpkg -P <pkg>

    Purge - removes the configuration too. RPM has no equivalent verb; `rpm -e` leaves an edited config as `.rpmsave`.

    Full guide
  • rpm -V <pkg>

    Verify installed files against the package manifest. Silence means every file matches - test the exit status, not the output.

    Full guide
  • rpm -V <pkg> (a failure)

    `S.5....T.` reads as size, MD5 and mtime all differing. A dot is a check that passed, so the string tells you what changed before you open the file.

    Full guide

Topic 103 - GNU and Unix commands

  • cmd 2>&1 | ...

    A pipe carries stdout only. `2>&1` is what puts stderr into it - which is why `cmd | grep x` sometimes misses text you can plainly see.

    Full guide
  • cmd > file 2>&1 (not: 2>&1 > file)

    Order matters. `> file 2>&1` sends both to the file; `2>&1 > file` points stderr at the terminal FIRST, then moves stdout, so the error escapes.

    Full guide
  • cmd | tee file | next

    Write to a file and keep the stream going. `sudo tee` is also how you write to a root-owned file, because `sudo echo x > file` redirects as YOU.

    Full guide
  • grep -E 'a|b' · grep '^x' · grep 'x$'

    Alternation needs `-E`; in basic regex `|` is literal. `^` and `$` are the two anchors, and both are examined by name.

    Full guide
  • cut -d" " -f1 file | sort | uniq -c | sort -rn

    The frequency-count idiom. `uniq` only collapses ADJACENT duplicates, so the `sort` before it is not optional.

    Full guide
  • awk '$4=="X" {print $1}' file

    When the test is about one specific field. `$0` is the whole line, `NF` the field count.

    Full guide
  • sed 's/old/new/' file · sed -n '2,4p' file

    Substitution on the way past, and line selection with `-n`. sed does NOT edit the file unless you pass `-i`.

    Full guide
  • ls | xargs cmd · find -print0 | xargs -0 cmd

    For commands that take arguments, not stdin. Use the NUL-separated pair when filenames may contain spaces.

    Full guide

Topic 104 - Devices, filesystems and the FHS

  • findmnt -no SOURCE,TARGET / /boot

    Which device is the system disk. Run this BEFORE anything destructive - device names shift when disks are added.

    Full guide
  • parted -s <disk> mklabel gpt / mkpart primary ext4 1MiB 100%

    GPT label and one aligned partition. Starting at 1MiB aligns to the erase block; `-s` is script mode.

    Full guide
  • mkfs.ext4 -L <label> <part> · blkid <part>

    Make the filesystem and read back its UUID and label - the two identifiers fstab can use.

    Full guide
  • tune2fs -l <part>

    Filesystem metadata. `Reserved block count` is 5% by default, which is why a fresh 4.9 G filesystem shows 4.6 G free.

    Full guide
  • UUID=<uuid> /mnt/x ext4 defaults,noatime 0 2

    The six fstab fields: device, mount point, type, options, dump, pass. `pass` is 1 for root, 2 for others, 0 to skip.

    Full guide
  • mount -a

    ALWAYS run this before rebooting after an fstab edit. A malformed line can stop the machine reaching a login prompt.

    Full guide
  • ls /dev/disk/by-uuid/ · ls /dev/disk/by-id/

    `by-uuid` follows the FILESYSTEM, `by-id` follows the HARDWARE. fstab wants the first; a script addressing a physical disk wants the second.

    Full guide
  • umount <part> && fsck -f -y <part>

    Unmount FIRST - always. `-f` forces the check past the clean flag. Exit 0 is clean, 1 means errors were found and corrected.

    Full guide

Topic 107 - Administrative tasks

  • useradd -m -c "<comment>" -s <shell> <user>

    Creates the account, the home directory from /etc/skel, and a private group. `useradd -D` shows the defaults it used.

    Full guide
  • usermod -aG <group> <user>

    The `-a` is not optional. `usermod -G` without it REPLACES every secondary group the user had.

    Full guide
  • chage -M <days> -W <days> <user> · chage -l <user>

    Maximum password age and warning period. The default max of 99999 is not "disabled", it is 273 years.

    Full guide
  • passwd -l <user> · passwd -u <user>

    Prepends `!` to the hash. Does NOT block key-based SSH - for that, set the shell to nologin or expire the account.

    Full guide
  • crontab -u <user> -l · crontab -e

    Five fields: minute, hour, day-of-month, month, day-of-week. `crontab -r` deletes the lot with no confirmation.

    Full guide
  • /etc/crontab and /etc/cron.d (SIX fields)

    System crontabs carry an extra USER column between the schedule and the command. A user crontab has no such field.

    Full guide
  • systemctl list-timers --all

    What the machine actually schedules. Shows NEXT and LAST, which cron cannot tell you at all.

    Full guide
  • systemd-analyze calendar "<OnCalendar expr>"

    Verify a schedule before trusting it. There is no cron equivalent - a mistyped cron line is discovered when the job does not run.

    Full guide