Essential Linux Commands Every Developer Should Know
Navigate, search, inspect and manage a Linux system with confidence. A practical tour of the commands developers reach for every day.
On this page
- Navigating the file system
- Creating, copying, moving and deleting
- Reading files
- Searching inside files with grep
- Finding files with find
- Pipes and redirection: combining commands
- Permissions with chmod and chown
- Processes: what's running?
- Disk and memory
- Networking basics
- Working on remote servers
- Getting help
- Recap
Whether you're deploying to a cloud server, working inside Docker, or just using a terminal on your Mac, sooner or later you'll be typing Linux commands. The good news is that a few dozen commands cover the vast majority of daily work.
Each section below shows the commands, the options you'll actually use, and real-world examples.
Navigating the file system#
pwd # where am I?
ls -lah # list everything: long format, hidden files, human-readable sizes
cd /var/log # go to an absolute path
cd .. # up one level
cd - # jump back to the previous directory
cd # go home (same as cd ~)Tab completion saves hours
Type the first few letters of a file or directory name and press Tab. The shell completes it for you, or shows the options if there's more than one match.
Creating, copying, moving and deleting#
mkdir -p projects/blog/src # create nested directories in one go
touch notes.txt # create an empty file (or update its timestamp)
cp config.yml config.yml.bak # copy a file
cp -r src/ backup/ # copy a directory recursively
mv draft.md posts/final.md # move and/or rename
rm old.log # delete a file
rm -r build/ # delete a directory and everything in itThere is no recycle bin
rm deletes immediately and permanently. Double-check paths before running rm -r, especially with wildcards or sudo. Adding -i makes rm ask before each deletion.
Reading files#
cat package.json # print a whole (short) file
less /var/log/syslog # scroll through a long file (q to quit, / to search)
head -n 20 app.log # first 20 lines
tail -n 50 app.log # last 50 lines
tail -f app.log # follow new lines as they're written, great for live logsSearching inside files with grep#
grep finds lines that match a pattern. It's one of the most useful tools you'll ever learn:
grep "ERROR" app.log # lines containing ERROR
grep -i "timeout" app.log # case-insensitive
grep -rn "TODO" src/ # search recursively, show line numbers
grep -v "DEBUG" app.log # lines that do NOT match
grep -c "404" access.log # count matching linesFinding files with find#
find . -name "*.py" # all Python files below the current directory
find /var/log -name "*.log" -mtime -1 # .log files modified in the last 24 hours
find . -type f -size +100M # files bigger than 100 MB
find . -type d -name node_modules # directories named node_modulesPipes and redirection: combining commands#
The real power of the command line comes from chaining small tools together. The pipe | sends one command's output into the next command's input:
# Top 5 IP addresses hitting your web server
cut -d' ' -f1 access.log | sort | uniq -c | sort -rn | head -5Read it left to right: take the first field (the IP address) from each line, sort the addresses, count the duplicates, sort by count with the highest first, and show the top five.
Redirection sends output to files:
ls -la > files.txt # write output to a file (overwrites it)
echo "done" >> build.log # append to a file
npm test > test.log 2>&1 # capture both normal output and errors
wc -l < data.csv # use a file as input: counts its linesPermissions with chmod and chown#
Run ls -l and you'll see lines like this:
-rwxr-xr-- 1 deploy www-data 2048 Oct 12 09:30 deploy.shThe permission string breaks down into three groups of three: the owner (rwx), the group (r-x) and everyone else (r--). Here r means read, w means write and x means execute.
chmod +x deploy.sh # make a script executable
chmod 644 index.html # owner: read/write, everyone else: read-only
chmod 755 scripts/ # owner: full access, everyone else: read and enter
sudo chown -R www-data:www-data /var/www/site # change owner and group recursivelyNumeric modes add up: read = 4, write = 2, execute = 1. So 7 = 4+2+1 (rwx), 5 = 4+1 (r-x) and 4 means read-only.
Processes: what's running?#
ps aux | grep node # find running node processes
top # live view of CPU and memory use (q to quit)
kill 12345 # politely ask process 12345 to stop
kill -9 12345 # force it to stop (last resort)Many systems also have htop, a friendlier, colourful alternative to top.
Disk and memory#
df -h # free disk space per filesystem
du -sh * # size of each item in the current directory
du -sh * | sort -h # ...sorted from smallest to largest
free -h # memory usageNetworking basics#
curl https://example.com # fetch a page
curl -I https://example.com # headers only: check status codes and caching
curl -X POST -H "Content-Type: application/json" \
-d '{"name": "Ada"}' https://httpbin.org/post
sudo ss -tlnp # which programs are listening on which ports
ping -c 4 example.com # is the host reachable?Working on remote servers#
ssh user@203.0.113.10 # log in to a server
scp report.pdf user@203.0.113.10:~/ # copy a file to it
rsync -avz ./site/ user@203.0.113.10:/var/www/site/ # sync a whole directory efficientlyGetting help#
You don't need to memorise every option, because the system documents itself:
man grep # the full manual (q to quit)
grep --help # a quick summary of options
history | grep docker # find that command you ran last weekAnd here's the best shortcut of all: press Ctrl+R and start typing to search your command history interactively.
Recap#
| Task | Commands |
|---|---|
| Navigate | pwd, ls, cd |
| Manage files | mkdir, touch, cp, mv, rm |
| Read files | cat, less, head, tail -f |
| Search | grep, find |
| Combine | pipes, >, >>, 2>&1 |
| Permissions | chmod, chown |
| System | ps, top, kill, df, du, free |
| Network | curl, ss, ssh, rsync |
Open a terminal and try each command as you read. Muscle memory is the real goal, and within a week you'll wonder how you ever worked without them.