Linux Cheat Sheet
Basic Commands
pwd # Print current working directory
ls # List files in directory
ls -l # Long listing format
ls -a # Show hidden files
cd /path/to/dir # Change directory
cd .. # Go up one directory
cd - # Switch to previous directory
mkdir new_dir # Create a directory
rm [Link] # Remove file
rm -r dir_name # Remove directory and its contents
cp source dest # Copy file or directory
mv oldname newname # Rename or move file
clear # Clear terminal
File & Directory Permissions
chmod 644 file # Set file permissions (rw-r--r--)
chmod 755 [Link] # Give execute permission (rwxr-xr-x)
chown user:group file # Change owner and group of file
File Viewing & Editing
cat [Link] # View file contents
tac [Link] # View file in reverse
less [Link] # Scroll through file
more [Link] # View file page by page
nano [Link] # Edit file in nano editor
vi [Link] # Edit file in vi editor
head -n 10 [Link] # Show first 10 lines
tail -n 10 [Link] # Show last 10 lines
tail -f logfile # Monitor file in real time
Process Management
ps aux # List running processes
top # Show system resource usage
htop # Interactive process viewer
kill PID # Kill process by PID
killall process # Kill process by name
pkill name # Kill by partial name
bg # Resume a job in the background
fg # Resume a job in the foreground
jobs # Show background jobs
User Management
whoami # Show current user
who # Show logged-in users
id user # Show user ID (UID) and group ID (GID)
adduser username # Add new user
passwd username # Change user password
deluser username # Remove user
usermod -aG groupname username # Add user to group
Networking
ip a # Show IP addresses
ifconfig # Show network interfaces (deprecated, use `ip a`)
ping [Link] # Test network connectivity
netstat -tulnp # Show open ports
ss -tulnp # Alternative to netstat
wget URL # Download file from URL
curl -O URL # Download file using curl
Disk Usage
df -h # Show disk usage in human-readable format
du -sh /path # Show folder size
lsblk # Show block devices
mount /dev/sdX /mnt # Mount a disk
umount /mnt # Unmount a disk
Searching & Finding Files
find / -name [Link] # Find file by name
find / -type f -size +50M # Find files larger than 50MB
grep "pattern" [Link] # Search for a pattern in a file
grep -r "pattern" /dir # Recursive search in directory
locate filename # Find file location (needs updatedb)
updatedb # Update locate database
Archiving & Compression
tar -cvf [Link] file/ # Create tar archive
tar -xvf [Link] # Extract tar archive
tar -czvf [Link] file/ # Create compressed tarball
tar -xzvf [Link] # Extract compressed tarball
zip [Link] file/ # Create zip archive
unzip [Link] # Extract zip archive
Package Management
Debian-based (Ubuntu, Debian)
apt update # Update package list
apt upgrade # Upgrade all packages
apt install pkg # Install package
apt remove pkg # Remove package
dpkg -i [Link] # Install .deb package
RedHat-based (Fedora, CentOS, RHEL)
yum install pkg # Install package (older systems)
dnf install pkg # Install package (newer Fedora/RHEL)
rpm -ivh [Link] # Install .rpm package
System Monitoring
uptime # Show system uptime
free -h # Show memory usage
df -h # Show disk usage
du -sh /dir # Show folder size
iostat # Show CPU usage (requires sysstat package)
vmstat # Show system performance
SSH & Remote Access
ssh user@host # Connect to remote server
ssh -p 2222 user@host # Connect using a custom port
scp file user@host:/path # Copy file to remote server
scp -r dir user@host:/path # Copy directory to remote server
rsync -av source dest # Sync files between local and remote
System Shutdown & Reboot
shutdown -h now # Shutdown system immediately
shutdown -r now # Reboot system immediately
reboot # Reboot system