Terminal and File Basics
July 16, 2026 ยท View on GitHub
The terminal gives precise, repeatable evidence about DNS, files, network listeners, certificates, and HTTP responses.
The Prompt and Working Directory
The shell waits at a prompt for a command. Check your current directory before creating, copying, or deleting files:
pwd
List files, including hidden files:
ls -la
Change directory:
cd my-first-site
Return to the parent directory:
cd ..
Paths
An absolute path begins from the filesystem root:
/var/www/example.dpdns.org/index.html
A relative path begins from the current directory:
./index.html
Before running a command with --delete, rm, administrator privileges, or recursive behavior, resolve both source and destination paths.
Create and Inspect Files
Create directories:
mkdir -p my-first-site/assets
Display a text file:
sed -n '1,120p' index.html
Search text recursively:
rg -n 'example.dpdns.org' .
Show file type:
file index.html
Standard Output and Errors
Commands can write normal output and error output. A command that prints nothing is not automatically successful.
Check the previous exit status in a POSIX-like shell:
echo $?
Zero normally indicates success. Scripts should verify status rather than search only for reassuring words.
Redirect output to a file:
dig NS example.dpdns.org > ns-check.txt
Redirect normal and error output:
curl -I https://example.dpdns.org > http-check.txt 2>&1
Review the file before sharing it.
Pipes
A pipe sends one command's output to another command:
dig A example.dpdns.org +short | sort -u
Pipelines can hide an earlier command failure unless the shell is configured to detect it. Use simple commands while learning and inspect the complete output during troubleshooting.
Quoting
Single quotes preserve text literally in common shells:
curl -I -H 'Host: example.dpdns.org' http://192.0.2.10
Double quotes allow variable expansion:
domain='example.dpdns.org'
dig A "$domain"
Never paste a command containing an unfamiliar variable, substitution, redirection, or encoded payload without understanding it.
Administrator Privileges
sudo runs a command with elevated privileges. Use it only for tasks that genuinely require system configuration, such as installing a package or changing a web server configuration.
Do not run an entire shell as root for convenience. Check a configuration before reloading a service.
Processes and Listening Ports
On Linux:
ps aux
sudo ss -lntup
On macOS:
ps aux
lsof -nP -iTCP -sTCP:LISTEN
Identify the program, address, and port before deciding whether a service is reachable.
Command History and Secrets
Shell history can retain commands. Avoid typing tokens and passwords directly in commands. Prefer a secret manager, protected prompt, or tool-specific credential store.
Do not include a secret in a URL. URLs may appear in history, logs, referrer data, and screenshots.
Practice Lab
mkdir -p domain-book-lab/site
cd domain-book-lab
pwd
printf '%s\n' 'example.dpdns.org' > planned-domain.txt
sed -n '1,20p' planned-domain.txt
find . -maxdepth 2 -type f -print
Expected result: one planned-domain.txt file containing the fictional domain. Remove the lab only after confirming the path:
cd ..
rm -r domain-book-lab
Review Questions
- What command confirms your current directory?
- Why should you inspect paths before
rsync --delete? - What is the difference between output and exit status?
- Why should an API token not appear directly in a shell command?
Continue to Build a Safe Practice Environment.