SE

Command line and Linux basics

Must-know concept2.5 hBeginner

Shell navigation, files, processes, permissions, pipes, and service inspection.

Backend work eventually lands on a shell: reading logs, checking ports, tailing a service, editing config, or proving that a container can reach a database. Linux basics make that work calm instead of mysterious.

The big idea

The shell is a programmable workbench. Small tools do one thing, print text, and compose through pipes and exit codes.

commanddo one thing
stdoutnormal output
stderrerrors/logs
exit codesuccess or failure

If you can navigate files, search text, inspect processes, and understand permissions, you can debug most local backend problems.

pwd                    # where am I?
ls -la                 # what is here?
cd app/api             # move around
find . -name '*.py'    # find by name
rg "DATABASE_URL"      # search file contents
sed -n '1,120p' file   # print a range
tail -f app.log        # follow new log lines

Use rg first when it exists. It is fast, respects ignore files, and keeps searches focused.

Pipes and redirection

docker compose logs api | rg "ERROR|Traceback"
curl -s http://localhost:8000/health > health.json
npm run build 2> build-errors.txt
pipe
Send one command's output into another command.
redirect
Write stdout or stderr to a file instead of the terminal.
exit code
0 means success; non-zero means failure. CI depends on this.
env var
A key-value setting passed into a process, like DATABASE_URL.

Permissions

Linux permissions answer three questions: who owns the file, which group can access it, and what everyone else can do.

ls -l deploy.sh
# -rwxr-x--- 1 app app 512 deploy.sh

The three permission groups are user, group, and other. The three operations are read, write, and execute. A script without execute permission can still be run with bash deploy.sh, but not as ./deploy.sh.

Processes and ports

ps aux | rg node
ss -ltnp
lsof -i :3000
kill -TERM <pid>

For backend services, "connection refused" usually means nothing is listening on that host and port. "Timeout" means packets are not coming back quickly enough. Those are different failures.

Services and logs

systemctl status nginx
journalctl -u nginx -n 100 --no-pager
docker compose ps
docker compose logs -f api

Read the first error and the last error. The first often explains the cause; the last is often just the crash repeating.

In practice

Pick one running app and answer: what process owns the port, where are its logs, what env vars did it start with, and what user runs it? That single exercise connects shell basics to real operations.

Key takeaways

  • The shell composes small tools with text, pipes, redirects, and exit codes.
  • Learn file navigation, `rg`, `sed`, `tail`, `ps`, `ss`, `lsof`, and service logs early.
  • Permissions are user/group/other crossed with read/write/execute.
  • Connection refused, timeout, and HTTP error responses point to different layers.
  • Every backend engineer should be able to inspect a local service from the terminal.

Checkpoint questions

Use these to test whether the lesson is clear enough to explain without rereading.

  1. 1How would you find a file, inspect its contents, and search inside it from the shell?
  2. 2What do user, group, and other permissions mean on a Linux file?
  3. 3How would you find which process is listening on a port?
  4. 4When would you use a pipe, redirect, environment variable, or exit code?

References

External resources for going deeper after the lesson above.