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 file.txt # 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 script.sh # Give execute permission (rwxr-xr-x)
chown user:group file # Change owner and group of file
File Viewing & Editing
cat file.txt # View file contents
tac file.txt # View file in reverse
less file.txt # Scroll through file
more file.txt # View file page by page
nano file.txt # Edit file in nano editor
vi file.txt # Edit file in vi editor
head -n 10 file.txt # Show first 10 lines
tail -n 10 file.txt # 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 google.com # 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 file.txt # Find file by name
find / -type f -size +50M # Find files larger than 50MB
grep "pattern" file.txt # 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 archive.tar file/ # Create tar archive
tar -xvf archive.tar # Extract tar archive
tar -czvf archive.tar.gz file/ # Create compressed tarball
tar -xzvf archive.tar.gz # Extract compressed tarball
zip archive.zip file/ # Create zip archive
unzip archive.zip # 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 package.deb # 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 package.rpm # 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