Everyday Linux commands: search, processes and packages
Lesson 9 of 11
9Everyday Linux commands: search, processes and packages
The big pictureWhen a server stops at 3 a.m. there is no graphical interface. These commands are your hands and eyes inside any Linux machine in the world.
What the picture shows: Five questions you ask every day, each with a command. Learn them in this order, since each leans on the pipes you already know.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
Imagine running a huge warehouse: find is a clerk finding a box by name, grep reads inside boxes for a word, ps lists who is working now, kill asks a worker to stop, df tells you how much space is left, and ssh is a gate into a warehouse in another city.
find walks the tree by criteria (-name, -type, -mtime, -size) and acts with -exec. grep -rn searches with regular expressions and line numbers. ps aux is a snapshot of processes, top/htop a live one, and kill sends a signal (SIGTERM 15 by default, SIGKILL 9 as a last resort). df -h covers file systems and du -sh folders. apt handles Debian/Ubuntu packages, curl -I fetches headers, ssh -i key user@host logs in with a key rather than a password, and tar -czf compresses.
Before You Start
🐚The shell and pipes
You know ls, cd, | and >.
The Core Idea
1Searching: find and grep
find finds files by name and properties; grep finds text inside them. Together they answer "where was this error written?" in a second.
find . -name "*.log" -mtime -1 # log files changed in the last day find . -type f -size +100M # files over 100 MB grep -rn "ERROR" logs/ # every line with ERROR, with its line number grep -c "404" access.log # how many lines mention 404
2Processes: ps, top and kill
Every running program is a "process" with a number (PID). ps aux | grep node finds node processes, top shows who is using the CPU right now, and kill PID asks one to stop politely.
kill -9 first. That signal kills instantly, without letting the process save files or close connections. Try a plain kill first and wait a few seconds.3Space and packages: df, du and apt
df -h says how much is left on each disk, and du -sh * says how much each folder here takes. sudo apt update && sudo apt install tree installs a program from the distribution's repository.
df -h / # free space on the main disk du -sh * | sort -h # folders here, smallest to largest sudo apt update sudo apt install -y tree
4Network and servers: curl, ssh and tar
curl -I https://example.com fetches only the response headers (remember the HTTP lesson). ssh user@server opens a terminal on a remote server, and scp copies to it. tar -czf backup.tar.gz project/ packs a folder into one compressed file.
curl -I https://example.com ssh -i ~/.ssh/id_ed25519 deploy@203.0.113.10 tar -czf backup.tar.gz project/ tar -xzf backup.tar.gz # unpack
Worked example
Problem: the server says "No space left on device". Fix: df -h shows the disk at 100%. sudo du -sh /var/* | sort -h reveals /var/log at 18 GB. find /var/log -name "*.gz" -mtime +30 finds old compressed logs; delete or move them and set up log rotation so it does not happen again.
Myth vs Reality
| Myth | Reality |
|---|---|
| The terminal is only for hackers and experts. | Twenty commands cover most of a developer's work, and you can learn them in a week. |
| kill -9 is the right way to stop anything. | It is the last resort. A plain kill lets the program save and shut down cleanly. |
Test your understanding
You want every line containing "timeout" in the logs folder. Which command?
grep searches inside file contents; find searches their names.
Which command tells you free disk space?
df covers whole file systems; du measures specific folders.
What is the safe way to log in to a server?
A key is far harder to guess than a password, and telnet is not encrypted at all.
Quick review cards
Check Your Understanding
What is the difference between find and grep?
find looks for the files themselves by their properties; grep looks for text inside files.
Why try kill before kill -9?
kill sends SIGTERM so the program saves and closes cleanly; -9 kills it instantly and may leave corrupt files.
How do you find the folder eating your space?
df -h to find the full disk, then du -sh * | sort -h inside it and downward until you find the folder.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Tools2
Done with this lesson?
Sign in to save your progress.