Basic Linux command list (cheat sheet)
This is a basic Linux command list you can keep as a quick reference. It covers the commands you will use most on Ubuntu, Debian, CentOS, AlmaLinux, Rocky Linux, and Fedora. Each section includes short examples you can copy and run. If you are working on a VPS, use the safety notes to avoid the common mistakes.
Before you start (quick safety rules)
- Know where you are: run
pwdbefore deleting or moving files. - Start read-only: check with
ls -lah, then act. - Use help pages:
command --helporman command. - Avoid risky defaults on servers: do not use
chmod 777unless you understand why it is needed, and be extra careful withrm -rf.
Basic Linux command list (quick cheat sheet)
Use this table when you just need the command fast. Detailed examples are below.
| Task | Command | Example |
|---|---|---|
| Show current folder | pwd | pwd |
| List files (human) | ls | ls -lah |
| Change folder | cd | cd /var/www |
| Copy / move | cp, mv | cp -a src/ backup/ |
| Search in files | grep | grep -R "error" /var/log |
| Check disk space | df | df -h |
| Check inodes | df | df -i |
| See CPU and RAM usage | top | top |
| Manage services | systemctl | systemctl status nginx |
| Find open ports | ss | ss -tulpn |
| SSH into a server | ssh | ssh root@203.0.113.10 |
Navigation commands (folders and paths)
Terminal basics and help commands
clear: clear the terminal screen.clearhistory: show your previous commands (great for repeating work).history | tail -n 20man: open the manual page for a command.man rsyncexit: close your shell session (or SSH session).exit
File and directory commands
touch: create an empty file or update timestamp.touch notes.txtmkdir: create a directory. Use-pfor nested folders.mkdir -p projects/app/logscp: copy files and folders. Use-rfor directories,-ato preserve permissions and timestamps.cp -a /var/www/html /var/www/html-backupmv: move or rename.mv old-name.txt new-name.txtrm: remove files. Use-rfor directories. On servers, consider interactive delete to be safe.rm -i file.txtrm -r folder/ln: create links. Use-sfor symlinks.ln -s /var/www/site/current public
View files and logs
cat: print file content (best for small files).cat /etc/os-releaseless: view a file page by page (great for configs and logs).less /var/log/sysloghead: show first lines.head -n 50 access.logtail: show last lines. Use-fto follow logs live.tail -n 200 error.logtail -f /var/log/nginx/error.log
Search and filter text
These are the basics you will use for troubleshooting and log searching.
grep: search for text in a file or directory. Useful flags:-R(recursive),-n(line numbers),-i(ignore case).grep -Rni "permission denied" /var/logfind: search for files by name, type, size, and more (very useful on servers).find /var/www -type f -name "*.log"wc: count lines, words, bytes.wc -l access.logsortanduniq: sort lines and deduplicate (often used together).sort file.txt | uniq -ccut: extract columns by delimiter.cut -d: -f1 /etc/passwd
Permissions and ownership (very important on VPS)
Linux permissions control who can read, write, and execute files. Most “site is broken” issues on servers come from wrong ownership or permissions.
chmod: change permissions.chmod 644 file.txtchmod 755 folder/chown: change owner and group.chown -R www-data:www-data /var/www/sitestat: show permissions and metadata.stat wp-config.php
| Common mode | Typical use | Meaning (owner/group/others) |
|---|---|---|
644 | Regular files (configs, text) | rw- / r-- / r-- |
600 | Sensitive files (keys, secrets) | rw- / --- / --- |
755 | Directories and executables | rwx / r-x / r-x |
Tip: If you are tempted to use 777, stop and fix ownership first. It is usually safer to set the correct user and group with chown than to open permissions for everyone.
User and identity commands
whoami: show the current user.whoamiid: show user ID, group ID, and groups.idgroups: list your groups.groupssudo: run a command as root (or another user).sudo systemctl restart nginxpasswd: change a user password (requires permissions).passwd
Processes and services
On a VPS, these commands help you spot high CPU or RAM usage and manage services safely.
ps: list running processes.ps aux | headtop: live view of CPU and RAM usage (pressqto quit).topkillandpkill: stop a process by PID or name.kill 1234pkill -f "php-fpm"systemctl: manage services on systemd distros.systemctl status nginxsystemctl restart mysqljournalctl: view systemd logs.journalctl -u nginx --since "1 hour ago"
Networking commands (IP, ports, DNS)
ip a: show IP addresses and interfaces.ip aip r: show routing table (helps diagnose “no internet”).ip rss: show listening ports and connections (modern replacement for netstat).ss -tulpnping: test basic connectivity.ping -c 4 1.1.1.1curl: test HTTP and APIs from the terminal.curl -I https://example.comdig(ornslookup): check DNS resolution.dig +short middlehost.com
Disk space, inodes, and memory
Disk space and inodes are different. A server can have free GBs but still fail uploads if it runs out of inodes (too many files).
df: disk usage by filesystem.df -hdf -i: inode usage by filesystem.df -idu: folder sizes (useful for finding big directories).du -sh /var/log/* | sort -hfree: memory usage (RAM and swap).free -hlsblk: list disks and partitions.lsblk
Archives and compression
tar: create or extract tar archives.tar -czf backup.tar.gz folder/tar -xzf backup.tar.gzzipandunzip: zip archives (if installed).zip -r site.zip public/unzip site.zip
Package management (install software)
Your package manager depends on your distro. Run cat /etc/os-release if you are unsure.
| Distro family | Update | Install package |
|---|---|---|
| Ubuntu / Debian | sudo apt update | sudo apt install nginx |
| Fedora / Rocky / Alma / RHEL | sudo dnf update | sudo dnf install nginx |
SSH and file transfer (remote server basics)
ssh: connect to a remote server.ssh user@server-ipscp: copy files over SSH.scp file.txt user@server-ip:/root/rsync: fast sync (best for large folders, keeps progress and can resume).rsync -avz ./site/ user@server-ip:/var/www/site/
If you are doing this on a VPS (Middlehost quick pointers)
A cheat sheet is great, but performance issues on websites are usually CPU, RAM, disk I/O, or misconfigured services. If you need a clean Linux environment to practice these commands, a Virtual Private Server (VPS) for Linux gives you full root access. For heavier workloads and isolation, consider dedicated servers for high traffic sites.
FAQs
What are the most important Linux commands for beginners?
Start with navigation and safety basics: pwd, ls -lah, cd, plus file commands like cp, mv, and rm -i. For troubleshooting, learn grep, tail -f, df -h, and top. These cover 80% of day-to-day server tasks.
How do I check disk space and inodes on Linux?
Use df -h to see disk space in GB and MB, and use df -i to see inode usage. Inodes are the “file count” capacity of a filesystem. If you run out of inodes, you can have free disk space but still cannot create new files, uploads, or cache files.
What is the difference between sudo and su?
sudo runs a single command with elevated permissions, based on your user’s sudo rules. su switches to another user, often root, for a full session. On servers, sudo is usually safer because it keeps actions scoped to one command and leaves a clearer audit trail in logs.
How do I find which process is using a port?
Run ss -tulpn to list listening ports and the process names. If you suspect a specific port, filter it like ss -tulpn | grep :80 or grep :443. This is useful when a web server fails to start because “address already in use” usually means another service is bound to that port.
What is the safest way to delete files on a Linux server?
First confirm your path with pwd and list targets with ls -lah. For single files, use rm -i so you get a confirmation prompt. For directories, consider deleting in smaller steps and avoid running rm -rf unless you are completely sure. When in doubt, move to a backup folder first.