๐ง Linux Cheat Sheet
๐ File & Directory Management
| Command |
Description |
ls -l |
List with long format |
ls -a |
Show hidden files |
cd /path |
Change directory |
pwd |
Show current directory |
mkdir dir |
Create directory |
rmdir dir |
Remove empty directory |
rm -r dir |
Remove directory and contents |
cp file1 file2 |
Copy file |
mv file1 file2 |
Move/rename file |
touch file |
Create empty file |
find /path -name "*.txt" |
Find files |
๐ File Viewing & Manipulation
| Command |
Description |
cat file |
View file |
tac file |
View file in reverse |
more file / less file |
Paginated view |
head -n 10 file |
First 10 lines |
tail -n 10 file |
Last 10 lines |
tail -f file |
Live log view |
cut -d':' -f1 /etc/passwd |
Column cut |
awk '{print $1}' file |
Print first field |
sed 's/foo/bar/g' file |
Replace in file |
๐๏ธ File Permissions
| Command |
Description |
chmod 755 file |
Set permission (u=rwx, g=rx, o=rx) |
chown user file |
Change owner |
chown user:group file |
Change owner and group |
umask |
Show default permission mask |
๐ฆ Package Management
Debian/Ubuntu (apt)
Bashapt update && apt upgrade
apt install <package>
apt remove <package>
Red Hat/CentOS/Alma (dnf/yum)
Bashdnf install <package>
dnf remove <package>
dnf update
Arch (pacman)
Bashpacman -Syu
pacman -S <package>
pacman -R <package>
๐ค User Management
| Command |
Description |
adduser username |
Add user |
passwd username |
Set user password |
deluser username |
Remove user |
usermod -aG sudo user |
Add to group |
id user |
Show user info |
who / w / users |
Logged-in users |
๐ง System Info & Resources
| Command |
Description |
uname -a |
Kernel and system info |
uptime |
System uptime |
top / htop |
Running processes |
free -h |
RAM usage |
df -h |
Disk usage |
du -sh * |
Folder sizes |
lscpu / lsblk / lsusb / lspci |
Hardware info |
dmesg |
Kernel logs |
vmstat |
Performance stats |
โ๏ธ Process Management
| Command |
Description |
ps aux |
All processes |
kill PID |
Kill process |
killall process_name |
Kill by name |
nice -n 10 command |
Set priority |
renice -n 5 PID |
Change priority |
๐ Permissions & Security
| Command |
Description |
chmod, chown, setfacl |
File permissions |
sudo |
Run as root |
visudo |
Edit sudoers safely |
firewall-cmd |
Firewalld (RHEL) |
ufw |
Firewall (Ubuntu) |
sshd, ss, iptables |
SSH & networking |
๐ Networking
| Command |
Description |
ip a / ifconfig |
Show IP address |
ip r / route |
Show routing |
ping 8.8.8.8 |
Test connection |
traceroute google.com |
Trace route |
netstat -tuln / ss -tuln |
Open ports |
dig domain.com / nslookup |
DNS lookup |
curl -I url |
HTTP headers |
wget url |
Download file |
๐ Archiving & Compression
| Command |
Description |
tar -czvf archive.tar.gz folder/ |
Compress folder |
tar -xzvf archive.tar.gz |
Extract archive |
zip -r file.zip folder/ |
Create ZIP |
unzip file.zip |
Extract ZIP |
gzip file / gunzip file.gz |
Compress/Extract GZ |
๐ ๏ธ Services & Startup
| Command |
Description |
systemctl start service |
Start service |
systemctl stop service |
Stop service |
systemctl status service |
Service status |
systemctl enable service |
Auto-start |
systemctl disable service |
Remove auto-start |
journalctl -xeu servicename |
Logs |
๐ Bash & Scripting Basics
| Syntax |
Description |
#!/bin/bash |
Shebang line |
var=value |
Declare variable |
echo $var |
Print variable |
read var |
Get user input |
if, elif, else, fi |
Conditional |
for, while, do, done |
Loops |
function fname {} |
Define function |
$(command) |
Command substitution |
"$@", $#, $?, $$ |
Script args, status, PID |
๐งช Useful Utilities
| Command |
Description |
cron, crontab -e |
Scheduled tasks |
logrotate |
Log file management |
env, export |
Environment variables |
alias, unalias |
Command shortcuts |
xargs, tee, watch |
Command chaining |
ncdu, iotop, glances |
Monitoring tools |
Text Only* * * * * /path/to/script.sh
โ โ โ โ โ
โ โ โ โ โโโโ Day of the week (0 - 7) (Sunday = 0 or 7)
โ โ โ โโโโโโ Month (1 - 12)
โ โ โโโโโโโโ Day of month (1 - 31)
โ โโโโโโโโโโ Hour (0 - 23)
โโโโโโโโโโโโ Minute (0 - 59)