Linux Survival Basics
Read-onlyFind the Largest Installed Packages
A Debian or Ubuntu system is low on disk and you need to see which installed packages occupy the most space.
Command
dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -nr | head -20
Before you run this
System impact: Read-only. Low when scoped to the shown target.
When not to use it: Do not remove large packages just because they are large; kernels, runtimes, and databases may be required.
Expected output
A size-sorted list of installed packages by KiB.
System impact
Read-only. Nothing changes. dpkg-query prints installed package sizes from metadata and sorts the largest first.
Recovery / rollback: no state is changed.
When to use it
Use before cleanup conversations, image slimming, or deciding which package families deserve review.
When not to use it
Do not remove large packages just because they are large; kernels, runtimes, and databases may be required.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -nr | head -20
132904 linux-image-6.8.0-60-generic
52288 python3
18320 nginx
8420 openssl
7488 curl
7240 libc6
6800 bash
980 base-files
256 zlib1g
250 zlib1g:i386
$ dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -nr | head -5
132904 linux-image-6.8.0-60-generic
52288 python3
18320 nginx
8420 openssl
7488 curl
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -nr | head -20dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -nr | head -5
next steps
Related commands
Find the Files Eating Your Disk
The disk was full, but guessing at folders was the slow part.
find /var -type f -printf '%s %p\n' | sort -nr | head -20
List Installed Package Versions
A package inventory beats memory when a server is drifting.
dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort
Count Failures by Test File
Turn noisy test logs into a ranked failure list.
grep -RhoE '[A-Za-z0-9_./-]+\.(test|spec)\.(js|ts|py|rb)' logs/ | sort | uniq -c | sort -nr | head
Find Broken or Leftover dpkg States
Not every package row is cleanly installed.
dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n' | awk '$1 !~ /^ii$/'
Find the Largest CI Logs
Huge logs often point to loops, noisy tests, or runaway debug output.
find logs/ -type f -printf '%s %p\n' | sort -nr | head -10
Study mapping
Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.
Useful for
- LPIC-1 style command-line practice
- LFCS style performance tasks
- Linux+ style troubleshooting review
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.