Skip to content

## ๐Ÿ“ Author

Birat Aryal โ€” birataryal.github.io
Created Date: 2025-06-23
Updated Date: Monday 23rd June 2025 07:52:15
Website - birataryal.com.np
Repository - Birat Aryal
LinkedIn - Birat Aryal
DevSecOps Engineer | System Engineer | Cyber Security Analyst | Network Engineer


๐Ÿง 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)

Bash
apt update && apt upgrade
apt install <package>
apt remove <package>

Red Hat/CentOS/Alma (dnf/yum)

Bash
dnf install <package>
dnf remove <package>
dnf update

Arch (pacman)

Bash
pacman -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

โฐ Cron Job Format

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)