linux cheat sheet

1. System Information

uname -aDisplay full system information
uname -rShow kernel release version
cat /etc/os-release or cat /etc/redhat-releaseShow distribution name and version
uptimeShow how long the system has been running + load average
hostnameDisplay hostname
hostname -IShow all local IP addresses
last rebootShow reboot history
dateCurrent date and time
calDisplay current month's calendar
wShow who is logged in and what they are doing
whoamiCurrent logged-in username

2. Hardware Information

dmesg | tail -50Show recent kernel messages
lscpu or cat /proc/cpuinfoCPU information
free -hMemory and swap usage (human readable)
lsblkList block devices and partitions
lspci -vList PCI devices with details
lsusb -vList USB devices with details
dmidecode --type systemBIOS / hardware information
hdparm -I /dev/sdaDetailed disk information

3. Performance Monitoring

top / htopReal-time process viewer
vmstat 1Virtual memory statistics (every 1 second)
iostat -x 1Disk I/O statistics (extended)
mpstat -P ALL 1CPU usage per core
sar -u 1 5CPU usage history (requires sysstat)
watch -n 1 df -hRefresh disk usage every second

4. User & Group Management

idShow current user and group IDs
who / wShow logged-in users
lastLogin history
useradd -m -s /bin/bash usernameCreate new user with home directory
passwd usernameChange user password
usermod -aG sudo usernameAdd user to sudo group
userdel -r usernameDelete user and home directory
groupadd groupnameCreate new group

5. File & Directory Commands

ls -laList all files with details
pwdPrint working directory
mkdir -p dir/subdirCreate directory including parents
rm -rf folderForce remove directory and contents
cp -r source destCopy directory recursively
mv old newRename or move file/folder
ln -s /path/to/target linknameCreate symbolic link
touch file.txtCreate empty file or update timestamp
tail -f /var/log/syslogFollow log file in real time

6. File Permissions (chmod)

Numeric (Octal)

ModePermissionTypical Use
777rwx rwx rwxFull access for everyone (avoid!)
775rwx rwx r-xShared group folders
755rwx r-x r-xScripts & public directories (most common)
644rw- r-- r--Regular files (most common)
600rw- --- ---Private files (only owner)

Symbolic Notation

Command ExampleMeaning
chmod u+x script.shAdd execute for owner
chmod go-w file.txtRemove write from group & others
chmod a+rx public/Add read+execute for all
chmod u=rw,go=r secret.txtOwner rw, others read-only
chmod +t /tmp/shareAdd sticky bit
chmod u+s /usr/bin/passwdSetuid bit (run as owner)
chmod g+s /projects/teamSetgid 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 ifconfigShow network interfaces and IPs
ping -c 4 google.comTest connectivity (4 packets)
curl ifconfig.meGet public IP address
dig google.comDNS lookup
ss -tuln or netstat -tulnList listening TCP/UDP ports
wget -c https://example.com/fileDownload file (resumable)

8. Archives (Tar & Compression)

tar czf archive.tar.gz folder/Create gzip compressed tar
tar xzf archive.tar.gzExtract .tar.gz
tar cjf archive.tar.bz2 folder/Create bzip2 compressed tar
zip -r archive.zip folder/Create zip archive
unzip archive.zipExtract zip file

9. Package Management

Debian/Ubuntu (apt)RHEL/Fedora (dnf/yum)Purpose
sudo apt updatesudo dnf check-updateRefresh package list
sudo apt install pkgsudo dnf install pkgInstall package
sudo apt search keyworddnf search keywordSearch for package
sudo apt remove pkgsudo dnf remove pkgUninstall package

10. Search & Find

grep -r "text" /path/Search recursively inside files
find / -name "file.txt"Find file by name
find . -type f -size +100MFind files larger than 100 MB
locate filenameFast search (run updatedb first if needed)

11. Process Management

ps aux | grep nameFind running process
kill -9 PIDForce kill process
pkill processnameKill all processes by name
nohup command &Run in background (survives logout)

12. SSH & Remote Access

ssh user@hostConnect via SSH
ssh -p 2222 user@hostSSH to custom port
ssh-keygen -t ed25519Generate new SSH key pair
ssh-copy-id user@hostCopy 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 -hHuman-readable disk usage
du -sh /pathTotal size of directory
du -ah | sort -rh | head -20Top 20 largest files/folders

15. Directory Navigation & Shortcuts

cd ..Go up one directory level
cd -Return to previous directory
cd ~ or cdGo to home directory
pushd /path & popdSave and return to directory stack

Post a Comment for "linux cheat sheet"