Linux Terminal Commands — Quick Reference
Essential Bash commands for file ops, navigation, search, processes, networking, and permissions
File ls — list directory contents
ls # current directoryls -la # all files with detailsls -lh # human-readable sizesls *.txt # pattern match-a shows hidden files. -l long format. -h with -l for readable sizes.
File cp — copy files/directories
cp file.txt dest/ # copy filecp -r dir/ dest/ # recursive copy directorycp -i file.txt bak/ # prompt before overwrite-r for directories. -v verbose. -i interactive (safe). -p preserve attributes.
File mv — move or rename
mv file.txt newname.txt # renamemv file.txt /path/dir/ # movemv -i *.txt backup/ # interactive bulk-i (interactive) or -n (no-clobber) to prevent.
File rm — remove files/directories
rm file.txt # remove filerm -r dir/ # remove directory recursivelyrm -rf dir/ # force, no prompts (DANGEROUS)rm -i *.log # prompt before each removalrm -rf is irreversible. Triple-check path. Use trash-cli for safer deletion.
Directory Ops
mkdir newdirmkdir -p a/b/c # create nested
rmdir emptydirrmdir -p a/b # remove parents if empty
File touch — create empty file or update timestamp
touch newfile.txt # create emptytouch file1 file2 file3 # multiple files-t option sets explicit timestamp.
View File Contents
cat file.txtcat f1 f2 > combined.txt
less longfile.logj/k scroll, q quit, /search
more file.txtspace next, Enter line
less for large files. cat is best for small files or piping.
Directory Navigation
pwd
cd /path/to/dircd .. # parentcd ~ # homecd - # previous dir
Search grep — search text in files
grep "pattern" file.txtgrep -r "TODO" . # recursive in current dirgrep -i "error" log.txt # case-insensitivegrep -n "fn" file.js # show line numbersgrep -v "debug" code.js # invert: exclude lines-r recursive. -i case-insensitive. -n line numbers. -v invert match (exclude).
Search find — search for files/dirs
find . -name "*.txt" # by name patternfind /var/log -type f # only filesfind . -size +10M # larger than 10 MBfind . -mtime -7 # modified in last 7 daysfind . -exec rm {} \; # execute on each result-name (case-sensitive), -iname (case-insensitive). -exec runs command on matches. {} is placeholder.
Locate Binaries
which nodewhich -a python # all matches
whereis gcc
View Processes
ps aux # all processesps -ef | grep node # filter
topq to quit, M sort by mem
htop(install: apt/brew)
Kill Processes
kill 1234 # SIGTERMkill -9 1234 # SIGKILL (force)
pkill -f "node app.js"
killall chrome
kill -9 (SIGKILL) does not allow graceful shutdown. Try kill (SIGTERM) first.
Process jobs / bg / fg — background tasks
command & # start in backgroundjobs # list background jobsfg %1 # bring job 1 to foregroundbg %1 # resume job in backgroundCtrl+Z to suspend current foreground job, then bg or fg to resume.
Perm chmod — change file permissions
chmod +x script.sh # add executechmod 755 app.js # rwxr-xr-xchmod 644 config.json # rw-r--r--chmod -R 755 dir/ # recursive755 = rwx (7) r-x (5) r-x (5)644 = rw- (6) r-- (4) r-- (4)
Perm chown — change file owner/group
chown alice file.txt # change ownerchown alice:staff file.txt # owner and groupchown -R www-data:www-data /var/www # recursiveDownload / HTTP
curl -O https://url/file.zipcurl -I https://site.com # headers only
wget URLwget -c file.zip # continue partial
Network Diagnostics
ping google.comping -c 4 host # count=4
traceroute google.com
nslookup example.com
Net ss / netstat — socket statistics
ss -tulpn # listening portsnetstat -tulpn # traditional (older)ss is modern replacement for netstat on Linux. -t TCP, -u UDP, -l listening, -p process.
Disk Usage
df -h # human-readabledf -i # inode usage
du -sh dir/ # summary human-readabledu -h --max-depth=1 # per-subdir
Memory / System
free -h
uname -a # all detailsuname -r # kernel version
File tar — tape archive (bundles files)
tar -cvf archive.tar dir/ # create tartar -xvf archive.tar # extracttar -czvf archive.tar.gz dir/ # create gzippedtar -xzvf archive.tar.gz # extract gzippedtar -tjvf archive.tar # list contents-c create, -x extract, -v verbose, -f file, -z gzip, -j bzip2.Order doesn't matter:
tar -zcvf = tar -czvf.
Compress Single Files
gzip file.txtgunzip file.txt.gz
zip -r out.zip dir/
unzip out.zip
gzip compresses files in-place (replaces original with .gz). Use tar for directories.
Basic Text
echo "text"echo $PATH # variable
head file.txthead -n 20 # 20 lines
tail -f logfile # follow livetail -n 50 # last 50 lines
Text wc — word/line/byte count
wc file.txt # lines words byteswc -l file.txt # line count onlywc -w file.txt # word countls -1 | wc -l # count files in dirSort & Unique
sort file.txtsort -r # reversesort -n # numeric
uniq sorted.txtsort file | uniq -c # count per value
uniq only removes adjacent duplicates. Pipe through sort first for full deduplication.
Stream Editors
sed 's/old/new/g' file.txtsed -i 's/foo/bar/g' file # in-place
awk '{print $1}' fileawk -F: '{print $1}' /etc/passwd
sed 's/old/new/' replaces first occurrence. g flag = global (all). -i edits file in-place.
Linux terminal commands — the ones you actually need
This covers the commands that come up in real development and server work. Not exhaustive — focused on what you'll run regularly on Linux servers, in Docker containers, or in a local terminal.
Files and navigation
ls -la— list all files including hidden, with permissions and sizescd -— go back to previous directoryfind . -name "*.log" -mtime +7— find log files older than 7 dayscp -r src/ dest/— recursively copy directorymv oldname newname— rename or moverm -rf dirname/— delete directory and contents (no confirmation, be careful)du -sh */— show disk usage of each directory in current folder
Searching text
grep -r "search term" ./— search recursively in all filesgrep -i "search" file.txt— case-insensitive searchgrep -n "error" app.log— show line numbersgrep -v "debug" app.log— exclude lines matching patterncat file.txt | grep "error" | tail -50— pipe: last 50 error lines
Processes and system
ps aux | grep node— find running Node processeskill -9 <PID>— force kill a process by IDlsof -i :3000— find what's using port 3000toporhtop— live process monitor (htop is better if available)df -h— disk space usage across mounted filesystemsfree -h— RAM usage summary
Permissions
chmod 755 script.sh— owner can rwx, others can rxchmod +x script.sh— make executablechown user:group file— change file ownersudo !!— re-run last command with sudo
Complete Developer Toolkit
Linux terminal commands are the backbone of server management, CI/CD pipelines, and development workflows. Pair this cheat sheet with our Git command cheat sheet — you'll use both constantly in any terminal session. Our cron generator builds the schedule expressions for Linux cron jobs, and our crontab descriptor decodes existing schedules you find in /etc/crontab or user crontabs. The regex tester is essential for grep, sed, and awk patterns — test your regex in the browser before running it against production log files.
For debugging server issues, our DNS lookup verifies domain resolution, our SSL expiry checker checks certificates, and our CORS error guide explains server configuration changes you'd make from the terminal. When your terminal scripts process JSON config files, our JSON formatter validates them before deployment. Our diff checker is a browser alternative to diff for comparing config files side by side. The Git error guide covers the git commands you'd run in the terminal when things go wrong. Our Python cheat sheet covers the Python scripts you commonly run from the Linux terminal.