Linux — Level by Level›Level 1 · Cheat sheet & self-check

Level 1 — Beginner: everyday commands · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · Your first terminal session

Where am I, who am I?

whoamiYour username
hostnameThe machine's name
pwdPrint working directory (where you are)
uname -aKernel and architecture
cat /etc/os-releaseWhich Linux distribution and version

Getting help

man lsThe manual page for ls (q to quit, / to search)
ls --helpShort built-in help for most commands
type cdIs it a built-in, an alias, or a program?
apropos networkSearch manual page descriptions

Save typing

Tab / Tab TabComplete a name / list the options
↑ / ↓Previous / next command
Ctrl+RSearch your command history
history | tail -20Your last 20 commands
Ctrl+C / Ctrl+LCancel the running command / clear the screen

02 · Files & directories

Move around

ls -lahList all files, long format, human-readable sizes
cd /var/logGo to an absolute path
cd .. / cd - / cdUp one level / previous directory / home
tree -L 2Directory tree two levels deep (may need installing)

Create, copy, move, delete

mkdir -p app/config/devCreate nested directories
touch notes.txtCreate an empty file (or update its timestamp)
cp -r src/ backup/Copy a directory recursively
mv old.txt new.txtRename (or move) a file
rm -i file.txtDelete, asking first
rm -r dir/Delete a directory and its contents (no undo!)

Find things

find /etc -name '*.conf'Files by name pattern
find /var/log -size +100MFiles larger than 100 MB
find . -mtime -1Modified in the last 24 hours
ln -s /opt/app/current appCreate a symbolic link

03 · Reading & searching text

Read

less /var/log/syslogPage through a file (/ search, n next, G end, q quit)
head -20 fileFirst 20 lines
tail -50 fileLast 50 lines
tail -f /var/log/syslogFollow a file as it grows (Ctrl+C to stop)

Search

grep -i error app.logLines containing 'error', any case
grep -rn 'listen' /etc/nginx/Search recursively, show file and line number
grep -v DEBUG app.logLines NOT matching
grep -C 3 'Traceback' app.log3 lines of context around each match

Pipes & redirection

cmd | grep x | wc -lCount lines matching x in cmd's output
cmd > out.txt / cmd >> out.txtWrite / append output to a file
cmd 2> errors.txtSend only errors to a file
cmd > all.txt 2>&1Output and errors to one file
sort | uniq -c | sort -rn | headCount and rank repeated lines

04 · Users, groups & permissions

Who am I?

idYour user ID, group ID and all groups
groups ashaGroups a user belongs to
getent passwd ashaA user's account entry

Change permissions and owners

chmod 640 app.envrw- for owner, r-- for group, --- for others
chmod u+x deploy.shAdd execute for the owner
chmod -R g+w shared/Recursively add group write
sudo chown app:app /srv/appChange owner and group

Users and sudo

sudo adduser deployCreate a user (Debian/Ubuntu helper)
sudo usermod -aG docker deployAdd a user to a group (-a = append!)
sudo -lWhat am I allowed to run with sudo?
sudo -u app whoamiRun a command as another user

05 · Processes, services & packages

Processes

ps aux --sort=-%mem | headTop memory users
ps -ef --forestProcesses with parent/child tree
top (or htop)Live view; press M (memory), P (CPU), q to quit
pgrep -a nginxFind processes by name
kill <pid> / kill -9 <pid>Ask to stop (SIGTERM) / force kill (SIGKILL)

Services (systemd)

systemctl status nginxRunning? Since when? Last log lines
sudo systemctl restart nginxRestart a service
sudo systemctl enable --now nginxStart now AND at every boot
systemctl list-units --type=service --state=failedServices that failed

Packages

sudo apt update && sudo apt install -y nginxDebian/Ubuntu
sudo dnf install -y nginxRHEL/Rocky/Alma/Fedora
apt list --installed | grep nginxIs it installed? (Debian/Ubuntu)
dpkg -L nginx / rpm -ql nginxFiles a package installed

06 · Checkpoint: a day on a server

Commands you'll use

systemctl status nginxIs it running? What went wrong?
sudo nginx -tCheck nginx config syntax, with file and line number
journalctl -u nginx --since '10 min ago'The service's recent logs
sudo ss -ltnpWhich process listens on which TCP port
curl -I http://localhostHTTP status code only
sudo du -ah /var/log | sort -rh | headLargest files and folders under /var/log