Level 1 — Beginner: everyday commands · wrap-up
Cheat sheet & self-check
Every command from this section on one page.
Where am I, who am I?
whoami | Your username |
hostname | The machine's name |
pwd | Print working directory (where you are) |
uname -a | Kernel and architecture |
cat /etc/os-release | Which Linux distribution and version |
Getting help
man ls | The manual page for ls (q to quit, / to search) |
ls --help | Short built-in help for most commands |
type cd | Is it a built-in, an alias, or a program? |
apropos network | Search manual page descriptions |
Save typing
Tab / Tab Tab | Complete a name / list the options |
↑ / ↓ | Previous / next command |
Ctrl+R | Search your command history |
history | tail -20 | Your last 20 commands |
Ctrl+C / Ctrl+L | Cancel the running command / clear the screen |
Move around
ls -lah | List all files, long format, human-readable sizes |
cd /var/log | Go to an absolute path |
cd .. / cd - / cd | Up one level / previous directory / home |
tree -L 2 | Directory tree two levels deep (may need installing) |
Create, copy, move, delete
mkdir -p app/config/dev | Create nested directories |
touch notes.txt | Create an empty file (or update its timestamp) |
cp -r src/ backup/ | Copy a directory recursively |
mv old.txt new.txt | Rename (or move) a file |
rm -i file.txt | Delete, 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 +100M | Files larger than 100 MB |
find . -mtime -1 | Modified in the last 24 hours |
ln -s /opt/app/current app | Create a symbolic link |
Read
less /var/log/syslog | Page through a file (/ search, n next, G end, q quit) |
head -20 file | First 20 lines |
tail -50 file | Last 50 lines |
tail -f /var/log/syslog | Follow a file as it grows (Ctrl+C to stop) |
Search
grep -i error app.log | Lines containing 'error', any case |
grep -rn 'listen' /etc/nginx/ | Search recursively, show file and line number |
grep -v DEBUG app.log | Lines NOT matching |
grep -C 3 'Traceback' app.log | 3 lines of context around each match |
Pipes & redirection
cmd | grep x | wc -l | Count lines matching x in cmd's output |
cmd > out.txt / cmd >> out.txt | Write / append output to a file |
cmd 2> errors.txt | Send only errors to a file |
cmd > all.txt 2>&1 | Output and errors to one file |
sort | uniq -c | sort -rn | head | Count and rank repeated lines |
Who am I?
id | Your user ID, group ID and all groups |
groups asha | Groups a user belongs to |
getent passwd asha | A user's account entry |
Change permissions and owners
chmod 640 app.env | rw- for owner, r-- for group, --- for others |
chmod u+x deploy.sh | Add execute for the owner |
chmod -R g+w shared/ | Recursively add group write |
sudo chown app:app /srv/app | Change owner and group |
Users and sudo
sudo adduser deploy | Create a user (Debian/Ubuntu helper) |
sudo usermod -aG docker deploy | Add a user to a group (-a = append!) |
sudo -l | What am I allowed to run with sudo? |
sudo -u app whoami | Run a command as another user |
Processes
ps aux --sort=-%mem | head | Top memory users |
ps -ef --forest | Processes with parent/child tree |
top (or htop) | Live view; press M (memory), P (CPU), q to quit |
pgrep -a nginx | Find processes by name |
kill <pid> / kill -9 <pid> | Ask to stop (SIGTERM) / force kill (SIGKILL) |
Services (systemd)
systemctl status nginx | Running? Since when? Last log lines |
sudo systemctl restart nginx | Restart a service |
sudo systemctl enable --now nginx | Start now AND at every boot |
systemctl list-units --type=service --state=failed | Services that failed |
Packages
sudo apt update && sudo apt install -y nginx | Debian/Ubuntu |
sudo dnf install -y nginx | RHEL/Rocky/Alma/Fedora |
apt list --installed | grep nginx | Is it installed? (Debian/Ubuntu) |
dpkg -L nginx / rpm -ql nginx | Files a package installed |
Commands you'll use
systemctl status nginx | Is it running? What went wrong? |
sudo nginx -t | Check nginx config syntax, with file and line number |
journalctl -u nginx --since '10 min ago' | The service's recent logs |
sudo ss -ltnp | Which process listens on which TCP port |
curl -I http://localhost | HTTP status code only |
sudo du -ah /var/log | sort -rh | head | Largest files and folders under /var/log |