1. System Information
| uname -a | Display full system information |
| uname -r | Show kernel release version |
| cat /etc/os-release or cat /etc/redhat-release | Show distribution name and version |
| uptime | Show how long the system has been running + load average |
| hostname | Display hostname |
| hostname -I | Show all local IP addresses |
| last reboot | Show reboot history |
| date | Current date and time |
| cal | Display current month's calendar |
| w | Show who is logged in and what they are doing |
| whoami | Current logged-in username |
2. Hardware Information
| dmesg | tail -50 | Show recent kernel messages |
| lscpu or cat /proc/cpuinfo | CPU information |
| free -h | Memory and swap usage (human readable) |
| lsblk | List block devices and partitions |
| lspci -v | List PCI devices with details |
| lsusb -v | List USB devices with details |
| dmidecode --type system | BIOS / hardware information |
| hdparm -I /dev/sda | Detailed disk information |
3. Performance Monitoring
| top / htop | Real-time process viewer |
| vmstat 1 | Virtual memory statistics (every 1 second) |
| iostat -x 1 | Disk I/O statistics (extended) |
| mpstat -P ALL 1 | CPU usage per core |
| sar -u 1 5 | CPU usage history (requires sysstat) |
| watch -n 1 df -h | Refresh disk usage every second |
4. User & Group Management
| id | Show current user and group IDs |
| who / w | Show logged-in users |
| last | Login history |
| useradd -m -s /bin/bash username | Create new user with home directory |
| passwd username | Change user password |
| usermod -aG sudo username | Add user to sudo group |
| userdel -r username | Delete user and home directory |
| groupadd groupname | Create new group |
5. File & Directory Commands
| ls -la | List all files with details |
| pwd | Print working directory |
| mkdir -p dir/subdir | Create directory including parents |
| rm -rf folder | Force remove directory and contents |
| cp -r source dest | Copy directory recursively |
| mv old new | Rename or move file/folder |
| ln -s /path/to/target linkname | Create symbolic link |
| touch file.txt | Create empty file or update timestamp |
| tail -f /var/log/syslog | Follow log file in real time |
6. File Permissions (chmod)
Numeric (Octal)
| Mode | Permission | Typical Use |
| 777 | rwx rwx rwx | Full access for everyone (avoid!) |
| 775 | rwx rwx r-x | Shared group folders |
| 755 | rwx r-x r-x | Scripts & public directories (most common) |
| 644 | rw- r-- r-- | Regular files (most common) |
| 600 | rw- --- --- | Private files (only owner) |
Symbolic Notation
| Command Example | Meaning |
| chmod u+x script.sh | Add execute for owner |
| chmod go-w file.txt | Remove write from group & others |
| chmod a+rx public/ | Add read+execute for all |
| chmod u=rw,go=r secret.txt | Owner rw, others read-only |
| chmod +t /tmp/share | Add sticky bit |
| chmod u+s /usr/bin/passwd | Setuid bit (run as owner) |
| chmod g+s /projects/team | Setgid bit on directory |
u = user/owner, g = group, o = others, a = all
+ = add, - = remove, = = set exactly
r = read, w = write, x = execute, t = sticky bit, s = setuid/setgid
7. Networking
| ip addr show or ifconfig | Show network interfaces and IPs |
| ping -c 4 google.com | Test connectivity (4 packets) |
| curl ifconfig.me | Get public IP address |
| dig google.com | DNS lookup |
| ss -tuln or netstat -tuln | List listening TCP/UDP ports |
| wget -c https://example.com/file | Download file (resumable) |
8. Archives (Tar & Compression)
| tar czf archive.tar.gz folder/ | Create gzip compressed tar |
| tar xzf archive.tar.gz | Extract .tar.gz |
| tar cjf archive.tar.bz2 folder/ | Create bzip2 compressed tar |
| zip -r archive.zip folder/ | Create zip archive |
| unzip archive.zip | Extract zip file |
9. Package Management
| Debian/Ubuntu (apt) | RHEL/Fedora (dnf/yum) | Purpose |
| sudo apt update | sudo dnf check-update | Refresh package list |
| sudo apt install pkg | sudo dnf install pkg | Install package |
| sudo apt search keyword | dnf search keyword | Search for package |
| sudo apt remove pkg | sudo dnf remove pkg | Uninstall package |
10. Search & Find
| grep -r "text" /path/ | Search recursively inside files |
| find / -name "file.txt" | Find file by name |
| find . -type f -size +100M | Find files larger than 100 MB |
| locate filename | Fast search (run updatedb first if needed) |
11. Process Management
| ps aux | grep name | Find running process |
| kill -9 PID | Force kill process |
| pkill processname | Kill all processes by name |
| nohup command & | Run in background (survives logout) |
12. SSH & Remote Access
| ssh user@host | Connect via SSH |
| ssh -p 2222 user@host | SSH to custom port |
| ssh-keygen -t ed25519 | Generate new SSH key pair |
| ssh-copy-id user@host | Copy public key to remote server |
13. File Transfer
| scp file.txt user@host:/tmp/ | Secure copy file to remote |
| scp -r folder/ user@host:/dest/ | Copy directory recursively |
| rsync -avz --progress src/ user@host:/dest/ | Efficient sync with progress |
14. Disk Usage
| df -h | Human-readable disk usage |
| du -sh /path | Total size of directory |
| du -ah | sort -rh | head -20 | Top 20 largest files/folders |
15. Directory Navigation & Shortcuts
| cd .. | Go up one directory level |
| cd - | Return to previous directory |
| cd ~ or cd | Go to home directory |
| pushd /path & popd | Save and return to directory stack |
Post a Comment for "linux cheat sheet"