This is just for my own reference to look up commands.
There are too many Linux commands to memorize them all. It's enough to remember the common ones and be able to look up the rest quickly when needed.

Table of Contents
- Quick Reference Table
- Files and Directories
- Viewing Files
- Text Processing
- Finding Files
- Permissions and Users
- Processes and Services
- Networking
- Package Management
- Disks and Mounting
- Compression and Archiving
- Logs and Troubleshooting
- Shell Miscellany
- Common One-Liners
Quick Reference Table
| Task | Common Commands |
|---|---|
| View directories | ls, tree |
| Change directories | cd, pwd |
| Copy, move, delete | cp, mv, rm |
| View files | cat, less, head, tail |
| Search text | grep, rg |
| Process text | awk, sed, cut, sort, uniq |
| Find files | find, locate, which |
| Change permissions | chmod, chown |
| View processes | ps, top, htop, kill |
| Networking | ip, ss, curl, ping, ssh |
| Archive and compress | tar, zip, gzip |
Files and Directories
ls
View directories:
ls
ls -l
ls -la
ls -lhCommon parameters:
-l: Detailed list-a: Show hidden files-h: Human-readable file sizes, e.g.,1.2G
cd and pwd
pwd
cd /var/www
cd ~
cd -cd - takes you back to the previous directory, which is quite useful.
cp
cp a.txt b.txt
cp -r src/ backup/
cp -a src/ backup/-a attempts to preserve permissions, timestamps, and other information, making it more reliable than -r when backing up directories.
mv
mv old.txt new.txt
mv file.txt /tmp/Can be used for both moving and renaming.
rm
rm file.txt
rm -r folder/
rm -rf folder/Be careful not to slip up with rm -rf. Especially when using variables, echo the path first, otherwise you will regret it if you delete the wrong thing.
mkdir
mkdir logs
mkdir -p app/data/cache-p automatically creates intermediate directories.
Viewing Files
cat
cat file.txtView small files directly. Don't use it for large files as it will flood your screen.
less
less app.logCommon operations:
/keyword: Searchn: Next resultq: Quit
head and tail
head -n 20 app.log
tail -n 50 app.log
tail -f app.logGenerally use tail -f for viewing logs.
nl
nl file.txtDisplays files with line numbers. Useful when troubleshooting configurations.
Text Processing
grep
grep "ERROR" app.log
grep -n "ERROR" app.log
grep -R "listen" /etc/nginx
grep -i "error" app.logCommon parameters:
-n: Show line numbers-R: Search directories recursively-i: Ignore case
If rg (ripgrep) is available on the system, I usually prefer it as it's much faster:
rg "ERROR"
rg "listen" /etc/nginxsed
sed -n '1,20p' file.txt
sed 's/old/new/g' file.txtOften used for replacing text or just viewing specific lines.
awk
awk '{print $1}' access.log
awk '{print $1, $9}' access.logProcesses text by columns. Frequently used for log analysis.
cut
cut -d':' -f1 /etc/passwd
cut -d',' -f1,3 data.csvUse this for simple column splitting; no need to write complex scripts right away.
sort and uniq
sort file.txt
sort -n numbers.txt
sort file.txt | uniq
sort file.txt | uniq -cVery handy for counting duplicates.
wc
wc -l file.txt
wc -c file.txtCounts lines and bytes.
Finding Files
find
find . -name "*.log"
find /var/log -type f -mtime -7
find . -type f -size +100MA few common conditions:
-name: By name-type f: Find files only-type d: Find directories only-mtime -7: Modified within 7 days-size +100M: Larger than 100M
which
which nginx
which pythonShows exactly where a command is coming from.
locate
locate nginx.confFast, but relies on an index. Newly created files might not be found.
Permissions and Users
chmod
chmod 644 file.txt
chmod 755 script.sh
chmod +x script.shCommon permissions:
644: Regular files755: Executable scripts or directories600: Sensitive files like private keys
chown
sudo chown user:group file.txt
sudo chown -R www-data:www-data /var/www/appYou often need to check this when website directory permissions are incorrect.
User-related
whoami
id
passwd
sudo useradd name
sudo usermod -aG sudo nameProcesses and Services
Viewing Processes
ps aux
ps aux | grep nginx
top
htopUse htop if you have it; it looks nicer.
Killing Processes
kill 1234
kill -9 1234
pkill -f nginxkill -9 is a forceful kill, not a universal fix button. Try a normal kill first, and use it only if that fails.
systemd Services
sudo systemctl status nginx
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl enable nginxView service logs:
journalctl -u nginx -f
journalctl -u nginx --since "1 hour ago"Networking
IP and Ports
ip addr
ip route
ss -tuln
ss -tulnpss -tulnp shows which process is occupying which port.
Connectivity
ping 1.1.1.1
curl -I https://example.com
curl http://127.0.0.1:3000Don't just ping to test HTTP services. A successful ping doesn't mean the website is alive.
SSH
ssh root@1.2.3.4
ssh -p 2222 user@1.2.3.4
scp file.txt user@1.2.3.4:/tmp/rsync
rsync -avz ./dist/ user@server:/var/www/app/
rsync -avz --delete ./dist/ user@server:/var/www/app/--delete removes extra files on the destination side, so think carefully before using it.
Package Management
Debian / Ubuntu:
sudo apt update
sudo apt install nginx
sudo apt upgradeCentOS / RHEL:
sudo yum install nginx
sudo dnf install nginxArch:
sudo pacman -S nginxopenSUSE:
sudo zypper install nginxCommands vary across distributions. Make sure not to copy the wrong one for your system.
Disks and Mounting
Viewing Disks
df -h
du -sh *
du -sh /var/logFinding large directories:
du -h --max-depth=1 / | sort -hBlock Devices
lsblk
blkid
sudo fdisk -lMounting
sudo mount /dev/sdb1 /mnt
sudo umount /mntCompression and Archiving
tar
tar -czvf archive.tar.gz folder/
tar -xzvf archive.tar.gz
tar -tzf archive.tar.gzzip
zip -r archive.zip folder/
unzip archive.zipgzip
gzip file.txt
gunzip file.txt.gzLogs and Troubleshooting
dmesg
journalctl -xe
journalctl -u service-name -f
tail -f /var/log/syslog
tail -f /var/log/nginx/error.logPort is occupied:
sudo lsof -i :80
sudo ss -tulnp | grep :80If configuration changes don't take effect, first check if the service was restarted, then check the logs. Many problems aren't due to missing configurations, but because the service simply didn't reload them.
Shell Miscellany
Environment Variables
env
printenv
export NODE_ENV=production
echo $PATHalias
alias ll='ls -lah'
alias gs='git status'Add them to ~/.bashrc or ~/.zshrc to make them permanent.
Executing Scripts
chmod +x script.sh
./script.shCron Jobs
crontab -e
crontab -lCommon One-Liners
Find large files:
find / -type f -size +500M 2>/dev/nullSearch for errors in logs:
grep -R --line-number "ERROR" /var/log 2>/dev/nullView the size of each folder in the current directory:
du -h --max-depth=1 . | sort -hSync website build artifacts:
rsync -avz --delete ./dist/ user@server:/var/www/site/View recent logs for a service:
journalctl -u nginx --since "2 hours ago" -fFind the process occupying a port:
sudo ss -tulnp | grep :3000Batch delete .tmp files:
find . -type f -name "*.tmp" -deleteIt's best to remove -delete and preview the results before executing this command:
find . -type f -name "*.tmp"Don't delete right away; deleting the wrong files is quite troublesome.