Linux CLI Cheat Sheet
Commands I use to find my way around a Linux machine: what it runs, its disks, files, permissions and network, plus a few text-processing one-liners.
Overview
| Task | Command |
|---|---|
| Distribution and version | cat /etc/os-release |
| List a folder, hidden files included | ls -la (-l long format, -a all) |
| Free space per filesystem | df -h |
| Size of each item in a folder, biggest first | du -sh * | sort -hr |
| Make a script executable for its owner | chmod u+x ./bin/script |
| Start a sub-shell / leave a shell | sh / exit or Ctrl+D |
| Hardware summary | lshw -short or inxi -Fx |
| Full hardware report | sudo lshw (sudo lshw -html > hardware.html); install it first on minimal Debian: sudo apt install lshw |
| SSD or spinning disk | lsblk -d -o NAME,ROTA (0 = SSD, 1 = HDD), or cat /sys/block/sda/queue/rotational |
| Disks, partitions and mount points | lsblk -o NAME,SIZE,MOUNTPOINT (the disk holding / and /boot/efi is the OS disk) |
Details
Network Interfaces and Addresses
ip -br addr # one line per interface: name, state, addresses (-br = brief)
ip addr show # full detail
ip link show # interface names and MAC addresses
ifconfig # older Linux, macOS
ipconfig /all # Windows
Permissions at a Glance
-rw-r--r-- becomes -rwxr--r-- after chmod u+x: the x in the owner's triplet means the owner may execute the file. Octal modes, directory rights and umask: Unix Permissions Grant Read, Write and Execute Separately to the Owner, the Group and Everyone Else.
Removing All class Attributes from HTML Files
# GNU sed (Linux)
find . -type f -name "*.html" -exec sed -i 's/ class="[^"]*"//g' {} +
# BSD sed (macOS) needs an empty backup suffix after -i
find . -type f -name "*.html" -exec sed -i '' 's/ class="[^"]*"//g' {} +
Use -name "*.html.erb" for Rails templates. Commit first: sed -i rewrites files in place with no undo.
"WARNING: terminal is not fully functional"
The remote shell doesn't recognise the terminal type sent by the client (common with newer terminals such as Ghostty), so pagers like less behind systemctl status fall back to a dumb mode.
export TERM=xterm-256color # current session
echo 'export TERM=xterm-256color' >> ~/.bashrc # future sessions, once
References
- man7.org: ip(8) -
ipoptions,-brincluded. - GNU coreutils: du invocation -
-sand-h. - os-release(5) - fields of
/etc/os-release. - Environment Variables Reach Child Processes Only When Exported -
env,exportandunset. - Linux Administration MOC - hub for Linux notes.
Review cards
Flashcard What does the `x` in the owner's triplet of file permissions mean?
The x means the owner may execute the file.
Flashcard How can you determine if a disk is an SSD or a spinning disk using the `lsblk` command?
Use lsblk -d -o NAME,ROTA where 0 indicates an SSD and 1 indicates a spinning disk, or check cat /sys/block/sda/queue/rotational.