Linux for Developers
Linux runs most servers, containers and build pipelines. Even if you develop on Windows, you will read Linux paths, run Linux commands and debug Linux machines.
One tree, no drive letters
Everything hangs under a single root /. Paths use forward slashes and are case-sensitive: App.log and app.log are different files.
| Path | Contents |
|---|---|
/home/<user> |
Home directories (~ is a shortcut for yours) |
/etc |
System-wide configuration |
/var/log |
Log files |
/usr/bin, /bin |
Programs |
/tmp |
Temporary files, may be deleted at any time |
/opt |
Optionally installed software |
/proc, /dev |
Virtual files for processes and devices |
Users and permissions
Every file has an owner, a group and permission bits for owner / group / others: read (r, 4), write (w, 2) and execute (x, 1).
ls -l deploy.sh # -rwxr-xr-- 1 anna dev 220 ... deploy.sh
chmod +x deploy.sh # make it executable
chmod 640 secrets.conf # owner rw, group r, others nothing
chown anna:dev file # change owner and group (needs privileges)
sudo systemctl restart nginx # run one command as root
Avoid running everything as root, and avoid chmod 777, which gives everyone full access.
Processes and services
ps aux | grep myapp # find a process
top # live view of CPU and memory (htop if installed)
kill <pid> # ask a process to stop (kill -9 forces it)
systemctl status myapp # state of a service
journalctl -u myapp -f # follow a service's logs
Most distributions use systemd to start and supervise services. Logs are in /var/log or in the journal.
Packages and getting help
Install software with the distribution’s package manager (apt on Debian/Ubuntu, dnf on Fedora/RHEL). Use man <command> or <command> --help for documentation.
Try it
Open a Linux shell (a WSL distribution works). Create a script, run it, then fix the “Permission denied” error with chmod. Find your five busiest processes with top and read the last 20 lines of a file in /var/log with tail -n 20.
Common mistakes
- Using `chmod 777` to fix a permission error, which gives everyone full access.
- Running everything as `root` instead of using `sudo` for single commands.
- Assuming `App.log` and `app.log` are the same file.
Check yourself
- What do the permission bits `rwxr-xr--` allow for owner, group and others?
- Where would you look for the logs of a service managed by systemd?
- Why is `chmod 777` a bad fix for a "Permission denied" error?