Command Line Essentials — DevOps

On the command line, you type a line and the shell (the program that reads what you type) runs it. A line you type is made of the command (the first word, the…

You log in to a production server for the first time. A production server is a computer that runs an app for real users. You open it from far away over SSH. All you get is one line of text and a blinking cursor. There is no mouse and there are no windows. The only way in is the command line (also called the terminal): you type a command, and the server answers in text.

Every line you type has three parts. Compare it with an order at a coffee stall: "iced coffee with milk, no sugar, for table five".

Through the whole DevOps track we manage one app: notes-api, the notes API from the Node.js track. It runs on one Ubuntu server (Ubuntu is a kind of Linux) named web-1, with the IP address 203.0.113.10. Its code is in the folder /srv/notes-api. The next lessons give the app the right file permissions, systemd, a deploy script, then Docker, CI/CD and monitoring. All of these are explained later.

One command, three parts

The shell is the program that reads what you type on the command line and runs it. The shell cuts the line you type at every space. The first word becomes the command, a word starting with - (or --) becomes a flag, and the rest become arguments (args):

Command line command flags args
ls -la /srv/notes-api ls -la /srv/notes-api
grep -r EACCES storage/logs/ grep -r EACCES, storage/logs/
mkdir -p storage/attachments/2026/10 mkdir -p storage/attachments/2026/10
cat config.js cat (empty) config.js

Into web-1: who you are, where you are

This morning a report arrived: attachment uploads on notes-api keep failing. You log in to the server over SSH (the SSH & Remote lesson of the Terminal track shows how), then check who and where you are. In this example, the text up to the $ sign is the prompt (it shows the shell is waiting for a command). What you type comes after the $ sign, and the other lines are the server's answers:

$ ssh [email protected]
deploy@web-1:~$ whoami
deploy
deploy@web-1:~$ pwd
/home/deploy
deploy@web-1:~$ cd /srv/notes-api
deploy@web-1:/srv/notes-api$ ls -la
total 56
drwxr-xr-x 7 deploy deploy 4096 Oct  8 17:40 .
drwxr-xr-x 3 root   root   4096 Sep 30 10:02 ..
-rw-r--r-- 1 deploy deploy   36 Sep 30 10:05 .env.example
drwxr-xr-x 8 deploy deploy 4096 Oct  8 17:35 .git
-rw-r--r-- 1 deploy deploy   28 Sep 30 10:05 .gitignore
-rw-r--r-- 1 deploy deploy  299 Oct  8 17:35 app.js
-rw-r--r-- 1 deploy deploy  402 Oct  8 17:35 config.js
-rw-r--r-- 1 deploy deploy  291 Oct  8 17:35 deploy.sh
-rw-r--r-- 1 deploy deploy  136 Oct  2 14:12 migrate.js
drwxr-xr-x 2 deploy deploy 4096 Oct  8 17:35 migrations
drwxr-xr-x 6 deploy deploy 4096 Oct  8 17:36 node_modules
-rw-r--r-- 1 deploy deploy  194 Oct  8 17:35 package.json
drwxr-xr-x 2 deploy deploy 4096 Oct  8 17:35 routes
drwxr-xr-x 4 deploy deploy 4096 Oct  8 17:40 storage

Health check: disk and logs

When an app has a problem, check two things first: whether the disk (the server's storage) is full, and what the log says (the file where the app records what happens).

deploy@web-1:/srv/notes-api$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        25G  9.0G   15G  39% /
deploy@web-1:/srv/notes-api$ tail -n 3 storage/logs/app.log
2026-10-09 08:10:56 ERROR EACCES: permission denied, open '/srv/notes-api/storage/attachments/c90e7a51.jpg'
2026-10-09 08:10:56 INFO POST /notes/3/attachments 500 9ms
2026-10-09 08:12:30 INFO GET /notes 200 11ms

Search the log for a pattern: grep

Next, grep shows how often that error happened, and ls -l storage shows who owns the folders:

deploy@web-1:/srv/notes-api$ grep -c EACCES storage/logs/app.log
3
deploy@web-1:/srv/notes-api$ grep -r EACCES storage/logs/
storage/logs/app.log:2026-10-09 07:20:11 ERROR EACCES: permission denied, open '/srv/notes-api/storage/attachments/7f3a9c1e.jpg'
storage/logs/app.log:2026-10-09 07:45:03 ERROR EACCES: permission denied, open '/srv/notes-api/storage/attachments/b21d4e08.png'
storage/logs/app.log:2026-10-09 08:10:56 ERROR EACCES: permission denied, open '/srv/notes-api/storage/attachments/c90e7a51.jpg'
deploy@web-1:/srv/notes-api$ ls -l storage
total 8
drwxr-xr-x 2 deploy   deploy   4096 Oct  8 17:40 attachments
drwxr-xr-x 2 www-data www-data 4096 Oct  9 00:00 logs

Nested folders: mkdir -p

Budi made the attachments folder yesterday with mkdir -p. He was logged in as deploy at the time. A new folder always belongs to the user who made it, and that is where the problem comes from. mkdir makes a folder, and -p (parents) also makes any parent folders that are missing:

deploy@web-1:/srv/notes-api$ mkdir storage/attachments/2026/10
mkdir: cannot create directory 'storage/attachments/2026/10': No such file or directory
deploy@web-1:/srv/notes-api$ mkdir -p storage/attachments/2026/10
deploy@web-1:/srv/notes-api$

Without -p, mkdir only makes the last folder, so its parent folder (2026) must already exist. With -p, mkdir makes 2026 and then 10. If all the folders already exist, mkdir -p prints nothing and gives no error. Creating, copying and deleting files is covered in the Creating & Deleting Files lesson of the Terminal track.

A mini shell: splitting a command with JavaScript

In the exercise you write the function parseCommand(cmd). It copies the shell's first step:

  1. Split the command text at every space with split(" ").
  2. The word at index 0 becomes the command.
  3. The other words starting with - go into flags. Check them with startsWith("-").
  4. The remaining words go into args.

So "cat config.json" gives { command: "cat", flags: [], args: ["config.json"] }. That line has no flag, but flags is still there as an empty array; it is not left out.

⚠️ What confuses people on a server terminal

TL;DR: On the command line, you type a line and the shell (the program that reads what you type) runs it. A line you type is made of the command (the first word, the program's name), flags (options for how it runs, starting with -; they can be combined, like -la, and have long forms, like --parents) and arguments (the rest: the file, folder or text it works on). On a server (a computer that runs an app): whoami and pwd to know which user you are and which folder you are in, cd to move to another folder, ls -la to see everything in a folder with its owner, and df -h for disk use. tail -n 20 file prints the last 20 lines of a log (the file where an app records events), grep pattern file searches for text (-c counts matching lines, -r goes through a folder), and mkdir -p makes a folder with its parent folders. Read an error from the right: the reason comes last.

⚡ One command, three parts

Write:

grep -r EACCES storage/logs/
Guess first: the first word is the command, and a word starting with - is a flag. The rest are arguments. How many arguments does this line have?

Two: EACCES (the text to look for) and storage/logs/ (the folder to look in). grep is the command, -r the flag.

Meaning: The shell (the program that reads what you type) cuts the line at every space. The first word becomes the command (the program that runs), a word starting with - becomes a flag (an option for how it runs), and the rest become arguments (what it works on).

⚡ Who you are, where you are

Write:

deploy@web-1:~$ whoami
deploy
deploy@web-1:~$ pwd
/home/deploy

Meaning: The text up to the $ sign is the prompt: a sign that the server (the computer the app runs on) is waiting for a command. whoami prints the user (account) you are using, here deploy. pwd prints the folder you are in, here /home/deploy. On a server, run these two commands before any other.

⚡ Read the end of the log, then search it

Write:

deploy@web-1:/srv/notes-api$ tail -n 3 storage/logs/app.log
deploy@web-1:/srv/notes-api$ grep -c EACCES storage/logs/app.log
3

Meaning: A log is a file where an app records what happens, and new lines are always added at the bottom. That is why tail -n 3 (the 3 belongs to the flag -n) takes the last 3 lines: the newest events. grep -c looks for the text EACCES (the error code for permission denied) in that file, and only prints how many lines match: 3.

⚡ Nested folders in one step

Write:

deploy@web-1:/srv/notes-api$ mkdir -p storage/attachments/2026/10
Guess first: mkdir makes a folder. You run it without -p, and the 2026 folder doesn't exist yet. What does mkdir answer?

The error No such file or directory. Without -p, mkdir only makes the last folder, so its parent folder must already exist.

Meaning: With -p (parents), mkdir also makes any parent folders that are missing. If all the folders already exist, mkdir -p prints nothing and gives no error.

What you will learn