Tool
Linux Cheatsheet
Look up chmod, find, tar, pipes, and other everyday Linux syntax in seconds.
Search a command or a task, then copy an example into the terminal. Press / to focus search.
66 shown
Shell
|
command1 | command2
Send one command’s output into the next.
ps aux | grep nginxFilter a process list
cat access.log | grep 404 | wc -lCount matching lines
ls -lt | headNewest files first
>
command > file command >> file
Write output to a file. > replaces, >> appends.
echo hello > out.txtOverwrite the file
echo more >> out.txtAppend to the file
ls > files.txtSave a listing
2>
command 2> file command > file 2>&1
Capture error output, or merge it with normal output.
make 2> errors.txtErrors only
cmd > all.log 2>&1Stdout and stderr together
cmd &> all.logSame, shorter form
&& ||
cmd1 && cmd2 cmd1 || cmd2
Run the next command only if the previous one succeeded or failed.
mkdir -p dist && cp app dist/Run copy only if mkdir worked
grep -q ready status.txt || echo missingPrint a message if grep found nothing
test -f .env && echo foundCheck that a file exists
$VAR
export NAME=value echo $NAME
Read and set environment variables.
export PATH="$PATH:/opt/bin"Add a directory to PATH
echo $HOMEPrint home directory
printenv PATHPrint PATH
quotes
'literal' "expand $VAR"
Single quotes keep text literal. Double quotes still expand $VAR.
echo 'keep $HOME as text'No variable expansion
echo "user is $USER"Expand $USER
grep "error 500" app.logPattern with a space
*
* ? [abc] **
Match many filenames without typing each one.
ls *.logAll .log files
rm file-?.txtOne-character wildcard
cp src/*.{js,ts} dist/js or ts files
tee
command | tee file
Print output and save it to a file at the same time.
make | tee build.logSee output and save it
echo ok | tee -a notes.txtAppend to a file
history
history !! !n Ctrl+R
Re-run a previous command.
history 20Last 20 commands
!!Run the previous command
!123Run history item 123
alias
alias name='command'
Short name for a command you type often.
alias ll='ls -lah'll → ls -lah
aliasList aliases
unalias llRemove an alias
echo
echo [text]
Print text. Useful in scripts and redirects.
echo helloPrint text
echo -n no-newlineNo newline
printf "%s\n" "$HOME"printf form
Files
ls
ls [options] [path]
List files in a directory.
lsNames only
ls -lahLong list, hidden, human sizes
ls -ltNewest first
cd
cd [path]
Change the current directory.
cdGo home
cd /var/logGo to a path
cd ..Up one level
cd -Previous directory
pwd
pwd
Show the current directory path.
pwdWhere am I
mkdir
mkdir [-p] dir
Create a directory. -p also creates parents.
mkdir logsOne folder
mkdir -p src/app/utilsNested folders
rm
rm [-r] [-f] path
Delete files or directories. Cannot undo.
rm file.txtDelete a file
rm -r old-dir/Delete a directory
rm -rf tmp/Force, no promptDestructive
cp
cp [-r] src dest
Copy files or directories.
cp a.txt b.txtCopy a file
cp -r src/ backup/Copy a directory
cp -p file.txt backup.txtKeep timestamps
mv
mv src dest
Move or rename a file.
mv old.txt new.txtRename
mv file.txt /tmp/Move to another folder
find
find <path> [expression]
Find files by name, time, type, or size.
find . -name "*.log"By filename
find /var -mtime -7Modified in the last 7 days
find . -type f -size +100MFiles larger than 100MB
find . -name "*.tmp" -deleteDelete matchesDestructive
touch
touch file
Create an empty file, or update its timestamp.
touch notes.txtCreate one file
touch a.txt b.txtCreate several
ln
ln -s target link
Create a shortcut (symbolic link) to another path.
ln -s /opt/app/bin/tool ./toolMake a symlink
ls -l toolConfirm the link
View
cat
cat file
Print a whole file.
cat README.mdPrint a file
cat a.txt b.txtConcatenate two files
cat > notes.txtType into a new file (Ctrl+D to end)
less
less file
Page through a file. q to quit, / to search.
less /var/log/syslogOpen a log
dmesg | lessPage command output
head
head [-n N] file
Show the first lines of a file.
head file.txtFirst 10 lines
head -n 20 file.txtFirst 20 lines
tail
tail [-n N] [-f] file
Show the last lines. -f follows a log as it grows.
tail file.txtLast 10 lines
tail -n 50 file.txtLast 50 lines
tail -f /var/log/nginx/access.logFollow a live log
wc
wc [-l] [-w] [-c] file
Count lines, words, or characters.
wc -l file.txtLine count
wc file.txtLines, words, bytes
diff
diff file1 file2
Show the difference between two files.
diff a.txt b.txtBasic diff
diff -u old.txt new.txtUnified diff
date
date [+format]
Print the current date, time, or Unix timestamp.
dateLocal date and time
date +%Y-%m-%dYYYY-MM-DD
date +%sUnix seconds
Text
grep
grep [options] pattern [file]
Find lines that match a pattern.
grep error app.logMatch in one file
grep -i error app.logIgnore case
grep -n -r "TODO" src/Recursive, with line numbers
grep -v debug app.logInvert: lines that do not match
sed
sed 's/old/new/g' file
Replace text in a file or stream.
sed 's/foo/bar/g' file.txtPrint replaced text
sed -i 's/foo/bar/g' file.txtEdit the file in place
sed '/^#/d' file.txtDrop comment lines
awk
awk '{print $N}' file
Print selected columns, or simple totals.
awk '{print $1}' file.txtFirst column
awk -F, '{print $1,$3}' data.csvCSV columns 1 and 3
awk '{sum+=$1} END {print sum}' nums.txtSum a column
cut
cut -d SEP -f N file
Take a column from delimited text.
cut -d',' -f1 data.csvCSV first column
cut -d: -f1 /etc/passwdUsername from passwd
cut -c1-10 file.txtFirst 10 characters
sort
sort [options] file
Sort lines. -n sorts numbers.
sort file.txtAlphabetical
sort -n nums.txtNumeric
sort -r file.txtReverse
uniq
sort file | uniq
Drop duplicate lines. Sort first.
sort file.txt | uniqUnique lines
sort file.txt | uniq -cCount each line
sort file.txt | uniq -dOnly duplicates
xargs
command | xargs [command]
Turn a list of names into arguments for another command.
find . -name "*.log" | xargs grep errorGrep in found files
cat urls.txt | xargs curl -ODownload each URL
find . -name "*.tmp" | xargs rmDelete found files
Process
ps
ps [options]
List running processes and PIDs.
ps auxAll processes
ps aux | grep nodeFind by name
ps -ef --forestProcess tree
top
top htop
Live CPU and memory view. q to quit.
topInteractive monitor
top -p 1234One PID
htopIf htop is installed
kill
kill [-SIGNAL] PID
Stop a process by PID. Try without -9 first.
kill 1234SIGTERM, polite stop
kill -15 1234Same as default SIGTERM
kill -9 1234Force killDestructive
pkill
pkill name killall name
Stop processes by name instead of PID.
pkill nginxBy name
killall nodekillall form
pgrep -a nodeShow matching processes
jobs
jobs bg fg command &
Run a command in the background, or bring it back.
sleep 60 &Start in background
jobsList jobs
fg %1Bring to foreground
bg %1Resume in background
nohup
nohup command &
Keep a command running after you disconnect.
nohup ./server &Survive logout
nohup npm start > app.log 2>&1 &Save output to a log
free
free -h
Show RAM and swap. uptime shows load.
free -hHuman-readable memory
uptimeUptime and load
uname
uname [-a] [-r] [-m]
Show kernel and architecture.
uname -aAll kernel info
uname -rKernel version
lscpuCPU details
watch
watch [-n N] command
Re-run a command every few seconds.
watch -n 1 df -hRefresh every second
watch -n 2 'ps aux | grep nginx'Watch a filtered process list
Network
ip
ip addr ip route
Show addresses and routes. Replaces ifconfig.
ip addrAddresses
ip routeRoutes
ip linkInterfaces
ping
ping [-c N] host
Check whether a host is reachable.
ping 8.8.8.8Until Ctrl+C
ping -c 4 example.comFour packets then stop
ss
ss -tuln
See listening ports. Replaces netstat.
ss -tulnListening TCP/UDP ports
ss -tulnpInclude process names
ss -tuln | grep :80Filter port 80
curl
curl [options] URL
Call an HTTP URL. Good for APIs and downloads.
curl https://example.comGET body
curl -I https://example.comHeaders only
curl -X POST -H 'Content-Type: application/json' -d '{"ok":true}' https://api.example.comJSON POST
curl -o file.tgz https://example.com/file.tgzSave to a file
wget
wget URL
Download a file.
wget https://example.com/file.tgzDownload
wget -c https://example.com/file.tgzResume a partial download
scp
scp src user@host:dest
Copy a file over SSH.
scp file.txt user@host:/tmp/Local → remote
scp user@host:/var/log/app.log .Remote → local
scp -r dist/ user@host:/var/www/Copy a directory
rsync
rsync -avz src dest
Sync directories. Copies only what changed.
rsync -avz ./src/ user@host:/opt/app/Sync to a server
rsync -avz --progress src/ dest/Show progress
rsync -avz --delete src/ dest/Delete extra files on dest
ssh
ssh user@host
Log in to a remote machine.
ssh user@192.168.1.10Password or key login
ssh -i ~/.ssh/id_ed25519 user@hostChoose a key file
ssh user@host -p 2222Custom port
lsof
lsof -i :port
See which process is using a port.
lsof -i :3000Who uses port 3000
lsof -i TCP:80TCP port 80
lsof -p 1234Files a PID has open
Archive
tar
tar -c|x -z -f archive.tar.gz [path]
Pack or unpack .tar.gz. z=gzip, c=create, x=extract, f=file.
tar -czf backup.tar.gz src/Create .tar.gz
tar -xzf backup.tar.gzExtract here
tar -tzf backup.tar.gzList contents
tar -xzf backup.tar.gz -C /tmp/Extract to a folder
gzip
gzip file gunzip file.gz
Compress or decompress a single file.
gzip file.txtCreates file.txt.gz
gunzip file.txt.gzRestore the file
gzip -k file.txtKeep the original
zip
zip archive.zip files unzip archive.zip
Create or extract a .zip archive.
zip backup.zip a.txt b.txtZip files
zip -r backup.zip src/Zip a directory
unzip backup.zipExtract here
unzip -l backup.zipList contents
df
df -h
Disk space by filesystem.
df -hAll filesystems
df -h .This directory’s disk
du
du -h [path]
Which folders are using space.
du -sh .Total for this folder
du -h --max-depth=1One level of subfolders
du -h | sort -hr | headLargest first
Permissions
chmod
chmod MODE file
Change permission bits. 755 = rwxr-xr-x, 644 = rw-r--r--.
chmod 755 script.shOwner rwx, others rx (scripts/dirs)
chmod +x script.shMake executable
chmod 644 file.txtOwner rw, others r (normal files)
chmod -R 755 dir/Recursive
chmod 777 fileWorld-writable, avoidDestructive
chown
chown user:group file
Change file owner and group.
chown www-data:www-data app.sockOne file
chown -R deploy:deploy /var/www/Recursive
sudo
sudo command su - user
Run one command as root, or switch user.
sudo apt updateOne command as root
sudo -u www-data commandRun as another user
su -Root shell
sudo visudoEdit sudoers safely
whoami
whoami id groups
Show the current user and groups.
whoamiUsername
idUID and groups
groupsGroup names
whoLogged-in users
Packages
apt
apt update apt install pkg
Install packages on Debian and Ubuntu.
sudo apt updateRefresh package list
sudo apt install curlInstall
apt search nginxSearch
sudo apt remove curlRemove
apt show curlPackage info
dnf
dnf install pkg yum install pkg
Install packages on Fedora, RHEL, and CentOS.
sudo dnf install curlInstall (Fedora/RHEL)
sudo dnf updateUpdate
dnf search nginxSearch
sudo yum install curlOlder yum form
Services
systemctl
systemctl start|stop|status|enable name
Start, stop, or enable a service.
systemctl status nginxIs it running?
sudo systemctl start nginxStart now
sudo systemctl restart nginxRestart
sudo systemctl enable nginxStart on boot
systemctl --failedFailed units
journalctl
journalctl -u name [-f]
Read service logs.
journalctl -u nginxThis service
journalctl -u nginx -fFollow live
journalctl -p err -n 50Recent errors
dmesg | tailKernel messages
How to use
Type a command name or what you want to do (unzip, permissions, kill a process). Filter by category if you like. Copy an example and paste it into your terminal. Press / to jump to search.
FAQ
- Is this a full manual?
- No. Each command keeps a syntax line and a few copy-ready examples. Use man or --help when you need every flag.
- Can I search in Chinese or English?
- Yes. Try find, chmod, 解压, 管道, or kill process. Any token in the name, example, or hint will match.
- Does it run commands on a server?
- No. This page only helps you look up syntax. Nothing is executed or uploaded.