Linux Commands Cheatsheet
Essential Linux commands for files, permissions, processes, and networking
Your data never leaves the browser — all processing is done locally 0 server requests
Files & Directories
-
ls -alList detailed directory contents including hidden files
-
pwdPrint the current working directory path
-
cd /var/logChange directory (cd - returns to previous location)
-
mkdir -p a/b/cCreate directories including all intermediate paths at once
-
rm -rf dirForce-delete a directory and all its contents ※ irreversible, double-check the path
-
cp -r src dstCopy a directory recursively including all subdirectories
-
mv old newMove or rename a file or directory
-
touch file.txtCreate an empty file or update its modification timestamp
-
ln -s 원본 링크명Create a symbolic link (shortcut) to a file or directory
-
find . -name "*.log"Find files matching a name pattern under the current path
-
find . -mtime -1Find files modified within the last 24 hours
Viewing & Searching File Contents
-
cat file.txtPrint the entire file contents at once
-
less file.txtScroll through a long file (q to quit, / to search)
-
head -n 20 file.txtPrint only the first 20 lines of a file
-
tail -f app.logFollow the end of a file in real time (useful for log monitoring)
-
grep -rn "검색어" .Search for text recursively and show file names and line numbers
-
grep -i "error" app.logSearch without case sensitivity
-
wc -l file.txtCount the number of lines in a file
-
diff a.txt b.txtCompare two files and show their differences
-
sort access.log | uniq -c | sort -nrCount duplicate lines and sort from most to least frequent
Permissions & Ownership
-
chmod 755 script.shSet permissions to rwxr-xr-x (owner: all; group/others: read+execute)
-
chmod +x script.shAdd execute permission to a file
-
chown user:group fileChange the owner and group of a file
-
chown -R www-data:www-data /var/wwwRecursively change ownership of a directory and all its contents
-
sudo 명령Execute a command with administrator (root) privileges
-
su - usernameSwitch to another user (- applies the login environment)
Processes & Services
-
ps aux | grep nginxSearch running processes for a specific name
-
topMonitor CPU and memory usage in real time (htop is more user-friendly)
-
kill -9 PIDForce-kill a process (try -15 for graceful shutdown first)
-
pkill -f "python app.py"Kill processes matching a command-line pattern
-
nohup ./run.sh &Keep a process running in the background after the terminal closes
-
jobsList background jobs in the current shell (fg %1 to bring one to foreground)
-
systemctl status nginxCheck the status of a service
-
sudo systemctl restart nginxRestart a service (also: start/stop/reload)
-
sudo systemctl enable --now nginxEnable a service to start on boot and start it immediately
-
journalctl -u nginx -fFollow service logs in real time
Networking
-
ip aShow network interfaces and their IP addresses
-
ping -c 4 google.comSend exactly 4 pings to check connectivity
-
curl -I https://example.comFetch only the HTTP response headers
-
wget https://example.com/file.zipDownload a file from a URL
-
ss -tulpnShow open ports and the processes using them (replaces netstat)
-
ssh user@host -p 22Connect to a remote server via SSH
-
scp file.txt user@host:/path/Copy a file to a remote server over SSH
-
rsync -avz src/ user@host:/dst/Sync only changed files (efficient for large transfers)
Disk & Compression
-
df -hShow disk usage in human-readable units
-
du -sh */Summarize disk usage per directory in the current location
-
free -hShow memory usage in human-readable units
-
lsblkDisplay disk and partition layout as a tree
-
tar -czvf backup.tar.gz dir/Compress a directory into a tar.gz archive
-
tar -xzvf backup.tar.gzExtract a tar.gz archive
-
zip -r archive.zip dir/Compress a directory into a zip archive
-
unzip archive.zipExtract a zip archive
System Info & Packages
-
uname -aPrint kernel version and system information
-
cat /etc/os-releaseShow the Linux distribution name and version
-
uptimeShow system uptime and load averages
-
hostname -IPrint only the server's IP address(es)
-
sudo apt update && sudo apt upgradeRefresh package lists and upgrade all packages (Debian/Ubuntu)
-
sudo apt install 패키지명Install a package (use dnf install on RHEL-based systems)
-
history | grep sshSearch through previously entered commands
Linux Commands: The Essential Toolkit
Linux commands follow a consistent pattern: command, options (flags starting with -), and arguments. Learning a core set of commands covering files, permissions, processes, and networking covers the vast majority of everyday tasks.
For file operations, master ls, cd, cp, mv, rm, find, and grep. For process management, ps aux, kill, systemctl, and journalctl cover most scenarios. For networking, ip a, ss -tulpn, and curl handle typical diagnostics.
⚠ Commands like rm -rf, chmod -R 777, and sudo operations are irreversible or can affect system security. Always verify the target path or scope before running them.
FAQ
- How do I list all files including hidden ones?
- Use ls -al. The -a flag shows hidden files (those starting with a dot) and -l shows the long format with permissions, owner, size, and modification date.
- How do I find and kill a process using a specific port?
- Run ss -tulpn | grep :PORT to find the PID, then kill -15 PID for a graceful shutdown or kill -9 PID to force kill. Always try -15 first.
- What is the difference between rm -rf and rmdir?
- rmdir only removes empty directories. rm -rf removes a directory and everything inside it without prompting. Always double-check your path before running rm -rf — it is irreversible.