Linux Cheat Sheet
Files, processes, permissions, systemd, disk, and user management on a Linux host — the commands engineers run every day.
Navigation
10pwdPrint the current working directory
lsList files in the current directory
ls -lahList all files with sizes, human-readable
ls -la DIR | grep '^d'Show only directories
cd DIRChange to a directory
cd -Jump to the previous directory
cd ~Change to the home directory
tree DIRShow a directory structure as a tree
realpath FILEPrint the fully resolved absolute path
readlink -f FILEResolve file or symlink to its target path
File Manipulation
12touch FILECreate an empty file or bump its mtime
cp SRC DSTCopy a file
cp -r SRC DIR/Copy a directory recursively
mv SRC DSTMove or rename
rm FILERemove a file
rm -rf DIRForce-remove recursively (careful!)
mkdir -p DIR/SUBCreate nested directories
ln -s TARGET LINKCreate a symbolic link
file FILEPrint the file type
du -sh * | sort -hrBiggest directories in the tree, sorted
stat FILEFull file metadata (size, perms, timestamps)
md5sum FILECompute an MD5 checksum
Viewing Files
11cat FILEPrint a file to stdout
less FILEView a file with scroll and search
head -n 20 FILEShow the first 20 lines
tail -f FILEFollow a file's new lines
tail -n 50 FILEShow the last 50 lines
nl FILENumbered output
wc -l FILECount lines in a file
cut -d: -f1 FILEExtract the first colon-delimited field
diff FILE1 FILE2Compare two files line by line
sort -u FILESort and deduplicate lines
uniq -c FILECount consecutive duplicate lines
Finding
9find DIR -name '*.log'Find files by name pattern
find DIR -mtime +7Files modified more than 7 days ago
find DIR -size +100MFiles larger than 100 MB
find DIR -type f -exec rm {} \;Execute a command per match
which CMDPrint the absolute path of a command
command -v CMDLocate a command (portable)
locate FILEFast filename lookup from the database
grep -rn 'pattern' DIRRecursive case-sensitive search
grep -rn -i 'error' /var/logCase-insensitive search across logs
Text Processing
9grep '^ERROR' FILELines starting with ERROR
grep -v 'pattern' FILELines that do NOT match
sed -i 's/OLD/NEW/g' FILEReplace all matches in place
sed -n '10,20p' FILEPrint lines 10 through 20
awk '{print $1}' FILEPrint the first column
awk 'NR>1{sum+=$3} END{print sum}' FILESum values in column 3
tr -d '\r' < FILEStrip carriage returns
paste -sd, FILEJoin lines with a comma
xargs -n1 echo < FILERun a command per input line
Processes
13ps auxList all user processes
ps aux --sort=-%mem | headTop memory consumers
pgrep -f nginxFind PIDs by command pattern
kill PIDSend SIGTERM (graceful)
kill -9 PIDForce kill (SIGKILL)
killall nginxSignal every process by name
pkill -f 'python app.py'Kill by full command line
nohup CMD &Run detached from the terminal
setsid CMDStart a new session, fully detached
nice -n 10 CMDRun with low priority
renice 5 PIDLower an existing process priority
top -o %MEMInteractive view sorted by memory
htopInteractive process viewer
File Permissions
12chmod 755 FILErwx owner, r-x group/others
chmod 644 FILErw owner, r group/others (default files)
chmod 750 DIRrwx owner, r-x group, none others
chmod +x FILEMake a file executable
chmod -R g+w DIRRecursively add group write
chown USER:GROUP FILEChange owner and group
chown -R USER DIRRecursively change the owner
chgrp GROUP FILEChange only the group
umask 022Default permissions for new files
setfacl -m u:USER:rw FILEGrant an ACL for one user
getfacl FILEView a file's ACLs
lsattr FILEShow Linux file attributes
System Information
10uname -aKernel and architecture details
cat /etc/os-releaseDistro name and version
uptimeUptime and load averages
free -hMemory usage, human-readable
df -hFilesystem usage by mount
df -iInode usage (full inodes = silent failures)
lscpuCPU model and core counts
dmesg | tailRecent kernel messages
hostnamectlHostname and OS info (systemd)
timedatectlTime zone and clock sync status
Disk & Storage
9lsblkBlock devices and mount points
blkidFilesystem type and UUID per partition
mountList mounted filesystems
mount /dev/SD1 /mntMount a device
umount /mntUnmount a filesystem
du -sh DIRTotal size of a directory
fdisk -l /dev/SDAList partitions on a disk
iostat -x 2Per-device I/O stats, 2s interval
pvs; vgs; lvsLVM layout at a glance
Users & Groups
10whoamiCurrent user name
idUID, GID, and groups of the user
useradd -m -s /bin/bash USERCreate a user with home and shell
usermod -aG sudo USERAdd the user to a group (append)
passwd USERSet or change a password
userdel -r USERRemove a user with their home
groupadd GROUPCreate a group
su - USERSwitch user with their environment
lastRecent login sessions
getent passwd USERLook up a user in the account database
Logs & Journal
9journalctl -u nginx.serviceLogs for one systemd unit
journalctl -u nginx -fFollow a service's live logs
journalctl --since '1 hour ago'Logs from the last hour
journalctl -b / --boot=-1This boot / previous boot
journalctl -k -bKernel messages since boot
journalctl -p errErrors and above only
tail -f /var/log/syslogFollow the system log
tail -n 200 /var/log/nginx/error.logTail the Nginx error log
logrotate -vf /etc/logrotate.confForce-run log rotation
Networking
10ip addrIP addresses on all interfaces
ip routeRouting table
ss -tlnpListening TCP ports and owner processes
ss -tn state establishedEstablished TCP connections
ping HOSTReachability and round-trip time
hostname -ILocal IP addresses only
nc -vz HOST PORTCheck a TCP port is open
curl -I https://HOSTFetch only response headers
resolvectl statusDNS resolver configuration (systemd)
ip link set eth0 upBring an interface up
Archiving & Transfer
10tar -czf DIR.tar.gz DIRCreate a gzipped archive
tar -xzf DIR.tar.gzExtract a gzipped archive
tar -tzf DIR.tar.gzList contents without extracting
tar -xzf FILE.tar.gz -C DIRExtract into a specific directory
tar -xf FILE.tar -C DIR --strip-components=1Extract without the top-level folder
zip -r ARCHIVE.zip DIRCreate a zip archive
unzip FILE.zip -d DIRExtract a zip
rsync -avz SRC USER@HOST:DESTSynchronize with compression
scp FILE USER@HOST:DESTCopy a file over SSH
dd if=FILE of=DEV bs=4M status=progressRaw block copy (e.g. a USB stick)