Cheat Sheet Library

Bash (Debian / Linux) Cheat Sheet

The standard Linux shell. Use man command or command --help for details on any command.

  • 91 entries
  • 12 sections
  • Updated
  • Reviewed
  • Click a command to see all its options

91 entries

On this page
CommandAction

Files & Folders #

CommandAction
Create an empty file / update its timestamp
Create nested folders
/ Copy a file / folder
Move or rename
/ Delete a file / folder
Force-delete, no questions (double-check the path!)
Print a file
Scroll a file (q to quit, / to search)
/ First / last 20 lines
Follow a log live
Count lines
Size of a folder
Detect the file type
CommandAction
Find files by name
Files bigger than 100 MB
Files changed in the last 24 h
Search in a file
Recursive, case-insensitive, with line numbers
Lines that do not match
/ Where a command comes from
Fast search via a database ( first)

Permissions & Ownership #

CommandAction
Make executable
rw-r--r-- (normal file)
rwxr-xr-x (folder / script)
Recursively give the owner read/write
Change the owner
sudo cmdRun as root
Root shell

Numbers: r=4 w=2 x=1 → add them per owner / group / others.

Processes #

CommandAction
All processes
Find a process
/ Live process monitor
kill PID / Stop / force-kill
Kill by name
cmd &Run in the background
/ / List jobs / bring to front / continue in background
Ctrl + ZPause the current program
Keep running after logout

System & Services #

CommandAction
Kernel info
Distro and version
How long it has been running + load
Memory usage
Disk space
Disks and partitions
Service status
Restart a service
Start now and at boot
Follow a service's logs
/ Reboot / power off

Users #

CommandAction
/ Current user / user and group IDs
Create a user (Debian)
Give admin rights
Change your password
Switch user

Network #

CommandAction
IP addresses
Routes / default gateway
Ping 4 times
Response headers only
/ Download a file
Listening ports and their programs
/ DNS lookup
Local IPs

Archives #

CommandAction
Create a .tar.gz
Extract a .tar.gz
Extract to a folder
/ Zip / unzip

Redirection & Chaining #

SyntaxMeaning
cmd > file / cmd >> fileWrite / append output
cmd 2> err.logWrite errors
cmd &> all.logOutput and errors
cmd > /dev/null 2>&1Discard everything
a | bPipe
a && b / a || bRun b if a succeeds / fails
cmd | tee fileShow on screen and write to a file
$(cmd)Use a command's output inside another command

Keyboard & History #

KeyAction
Tab (twice)Autocomplete / show options
Ctrl + RSearch history
Ctrl + A / Ctrl + EStart / end of line
Alt + B / Alt + FWord back / forward
Ctrl + U / Ctrl + KCut before / after the cursor
Ctrl + WCut the previous word
Ctrl + YPaste what you cut
Ctrl + CStop the command
Ctrl + DExit the shell (end of input)
!!Repeat the last command (sudo !! = again as root)
!$Last argument of the previous command
Show history

Variables & Scripts #

#!/usr/bin/env bash
set -euo pipefail          # stop on errors, unset variables and pipe failures

name="Milan"               # no spaces around =
echo "Hello $name"
export API_KEY="abc"       # make it visible to child programs

for f in *.txt; do
  echo "Processing $f"
done

if [ -f config.json ]; then
  echo "exists"
fi

Run it with chmod +x script.sh && ./script.sh. Aliases go in ~/.bashrc, and source ~/.bashrc reloads it.