Linux Cheatsheet
Practical Linux command cheatsheet organized by category: file operations, text processing, networking, process management, disk usage, permissions, and more for quick reference
94 commands
lsList files and directories
ls -lacpCopy files or directories
cp -r src/ dest/mvMove or rename files/directories
mv old.txt new.txtrmRemove files or directories
rm -rf directory/touchCreate empty file or update timestamp
touch newfile.txtcatDisplay file contents
cat file.txtlessView file contents page by page
less largefile.logheadDisplay the beginning of a file
head -n 20 file.txttailDisplay the end of a file
tail -f /var/log/sysloglnCreate hard or symbolic links
ln -s /path/to/target link_namefileDetermine file type
file image.pngstatDisplay detailed file information
stat file.txtcdChange directory
cd /var/logpwdPrint working directory
pwdmkdirCreate directories
mkdir -p parent/child/dirrmdirRemove empty directories
rmdir empty_dirfindSearch for files and directories
find / -name '*.log' -mtime -7locateFast file search using database
locate nginx.conftreeDisplay directory tree structure
tree -L 2duDisplay directory disk usage
du -sh /var/*chmodChange file permissions
chmod 755 script.shchownChange file owner
chown user:group file.txtchgrpChange file group
chgrp developers project/umaskSet default file creation permissions
umask 022setfaclSet file access control lists
setfacl -m u:user:rwx filegetfaclGet file access control lists
getfacl file.txtpsDisplay running processes
ps aux | grep nginxtopReal-time process monitoring
top -u usernamehtopInteractive process viewer
htopkillSend signal to a process
kill -9 1234killallKill processes by name
killall nginxbgResume stopped job in background
bg %1fgBring background job to foreground
fg %1nohupRun command immune to hangups
nohup ./script.sh &niceRun command with modified priority
nice -n 10 ./heavy_task.shsystemctlManage systemd services
systemctl restart nginxipManage network interfaces and routing
ip addr showpingTest network connectivity
ping -c 4 google.comcurlTransfer data from/to a URL
curl -X POST -d '{"key":"val"}' https://api.example.comwgetDownload files from the web
wget https://example.com/file.tar.gzssDisplay socket statistics
ss -tulnpnetstatDisplay network connections and routing
netstat -tulnptracerouteTrace packet route to host
traceroute google.comdigDNS lookup utility
dig example.com MXnslookupQuery DNS name servers
nslookup example.comiptablesManage firewall rules
iptables -L -nscpSecure copy over SSH
scp file.txt user@host:/path/rsyncEfficiently sync files
rsync -avz src/ user@host:dest/dfDisplay filesystem disk usage
df -hmountMount a filesystem
mount /dev/sdb1 /mnt/usbumountUnmount a filesystem
umount /mnt/usbfdiskManage disk partitions
fdisk -llsblkList block devices
lsblkmkfsCreate a filesystem (format)
mkfs.ext4 /dev/sdb1fsckCheck and repair filesystem
fsck /dev/sda1whoamiDisplay current username
whoamiidDisplay user and group IDs
id usernameuseraddCreate a new user
useradd -m -s /bin/bash newuseruserdelDelete a user
userdel -r usernameusermodModify a user account
usermod -aG docker usernamepasswdChange user password
passwd usernamesuSwitch to another user
su - rootsudoExecute command as superuser
sudo apt updategroupsDisplay user's groups
groups usernameapt updateUpdate package lists (Debian/Ubuntu)
sudo apt updateapt installInstall packages (Debian/Ubuntu)
sudo apt install nginxapt removeRemove packages (Debian/Ubuntu)
sudo apt remove nginxapt upgradeUpgrade installed packages (Debian/Ubuntu)
sudo apt upgradeapt searchSearch for packages (Debian/Ubuntu)
apt search nodejsyum installInstall packages (RHEL/CentOS)
sudo yum install nginxyum removeRemove packages (RHEL/CentOS)
sudo yum remove nginxyum updateUpdate packages (RHEL/CentOS)
sudo yum updatednf installInstall packages (Fedora)
sudo dnf install nginxunameDisplay system information
uname -ahostnameDisplay or set hostname
hostname -IuptimeDisplay system uptime
uptimedateDisplay or set date/time
date '+%Y-%m-%d %H:%M:%S'freeDisplay memory usage
free -hlscpuDisplay CPU information
lscpudmesgDisplay kernel messages
dmesg | tail -20journalctlView systemd journal logs
journalctl -u nginx -fenvDisplay environment variables
env | grep PATHexportSet environment variable
export PATH=$PATH:/usr/local/bingrepSearch for text patterns
grep -rn 'error' /var/log/sedStream editor for text transformation
sed -i 's/old/new/g' file.txtawkPattern scanning and text processing
awk '{print $1, $3}' file.txtsortSort lines of text
sort -k2 -n file.txtuniqRemove or detect duplicate lines
sort file.txt | uniq -cwcCount lines, words, bytes
wc -l file.txtcutExtract fields from text
cut -d':' -f1 /etc/passwdtrTranslate or delete characters
echo 'HELLO' | tr 'A-Z' 'a-z'diffCompare files line by line
diff file1.txt file2.txtteeRead stdin and write to stdout and files
echo 'log' | tee output.logxargsBuild command arguments from stdin
find . -name '*.log' | xargs rm