Mini-guide: Terminal (CLI)
Tip jar 🫙 expatriotic@walletofsatoshi.com
Donations
Bitcoin paynym = +expatriotic
Monero QR

88D6SZFBA6fFhYGdnY4c57dTAJD6jyqRTfCKwHjZrfdnhd8phAMYnDQWSJrqyAmgVHV7mDU6soaHogZvno1AUXp79DwtWvK
Learn to use a terminal as a sys admin (system administrator). For every command, I will first show its abstract syntax, then provide a real-world example and explain why and when you would use it.
System Information
Command:
uname -a- Purpose: Displays all system kernel information.
- Real-world Example:
uname -a - Explanation: This shows you the kernel version, hostname, and CPU architecture. It's a quick way to confirm you're on the right machine and that it's running a 64-bit kernel (
x86_64).
Command:
hostnamectl- Purpose: Shows the system's hostname and OS details.
- Real-world Example:
hostnamectl
- Explanation: This provides a clean summary of your server's name, the operating system (e.g., Ubuntu 24.04 LTS), and the kernel version.
Navigation & Directory Management
Command:
pwd- Purpose: Prints the Working Directory (tells you "where am I?").
- Real-world Example:
pwd - Explanation: This will output your current path, for example,
/home/bitcoin. You'll use this constantly to orient yourself before you move or delete files.
Command:
ls -la- Purpose: Lists files and directories.
- Real-world Example:
ls -la /var/log
- Explanation: This is a "power-user" version of
ls. The-lflag gives a long list (showing permissions, owner, size). The-aflag shows all files, including hidden "dotfiles" (like.bashrc). This is how you inspect the contents and permissions of a directory.
Command:
cd <directory>- Purpose: Change Directory.
- Real-world Example:
cd /var/log
- Explanation: This moves your terminal session into the
/var/logdirectory. All commands you run next will be from this new location. (Usecd ~to return to your home directory).
Command:
mkdir <dirname>- Purpose: Make Directory.
- Real-world Example:
mkdir ~/projects - Explanation: This creates a new directory named
projectsinside your home directory (~is a shortcut for your home).
File Management
Command:
touch <filename>- Purpose: Creates a new, empty file.
- Real-world Example:
touch ~/projects/NOTES.md - Explanation: This creates an empty file named
NOTES.mdinside theprojectsdirectory you just made.
Command:
cp <source> <destination>- Purpose: Copies files or directories.
- Real-world Example:
cp /etc/ssh/sshd_config ~/projects/sshd_config.bak
- Explanation: This is a critical sysadmin task. It copies the main SSH configuration file into your
projectsfolder with a.bak(backup) extension. You always do this before editing a critical configuration file, just in case you break it.
Command:
mv <source> <destination>- Purpose: Moves or renames a file.
- Real-world Example:
mv ~/projects/NOTES.md ~/projects/README.md
- Explanation: This renames the
NOTES.mdfile toREADME.mdwithin the same directory. You also usemvto move a file to a different directory.
Command:
rm <filename>- Purpose: Removes (deletes) a file.
- Real-world Example:
rm ~/projects/sshd_config.bak - Explanation: This deletes the backup file. Be careful!
rmis permanent and has no "undo" or "recycle bin." (To delete a directory, you userm -r <dirname>).
Viewing & Searching Files
Command:
cat <file>- Purpose: Catenates (dumps) the entire content of a file to the screen.
- Real-world Example:
cat /etc/os-release - Explanation: This is for reading short files. It will display the OS version information all at once. Do not use this on large log files.
Command:
less <file>- Purpose: Opens a file in a pager, letting you scroll.
- Real-world Example:
less /var/log/syslog - Explanation: This is the proper way to read a large file. You can use your arrow keys to scroll up and down. Press
qto quit.
Command:
tail -f <file>- Purpose: Shows the "tail" (end) of a file and follows it, printing new lines in real-time.
- Real-world Example:
tail -f /var/log/syslog
- Explanation: This is one of the most useful diagnostic commands. It lets you watch a log file live as events are happening. Press
Ctrl+Cto stop.
Command:
grep <pattern> <file>- Purpose: Searches for a specific text pattern inside a file.
- Real-world Example:
grep "error" /var/log/syslog
- Explanation: This will search the entire
syslogfile and print only the lines that contain the word "error". This is how you find problems quickly.
User & Group Management
Command:
sudo adduser <username>- Purpose: Creates a new user.
- Real-world Example:
sudo adduser bitcoin
- Explanation: This is the recommended way to add a user in Ubuntu. It will interactively prompt you to create a password and set up the user's home directory (
/home/bitcoin).
Command:
su - <username>- Purpose: Switch User.
- Real-world Example:
su - bitcoin
- Explanation: This logs you in as the
bitcoinuser. The dash (-) is critical: it loads the user's full profile and environment, just as if they logged in fresh. You will be prompted for bitcoin's password. (Typeexitto return to your original user).
Command:
w- Purpose: Shows who is logged in and what they are doing.
- Real-world Example:
w
- Explanation: A quick way to see all active user sessions on the machine.
Package Management (Software)
Command:
sudo apt update- Purpose: Updates your system's local list of available software.
- Real-world Example:
sudo apt update
- Explanation: This command does not install or upgrade any software. It only refreshes the catalog, checking for new versions. You should always run this before installing or upgrading.
Command:
sudo apt install <package>- Purpose: Installs or upgrades a software package.
- Real-world Example:
sudo apt install btop
- Explanation: This will download and install
btop, our preferred system monitor.
Command:
sudo apt remove <package>- Purpose: Removes a software package.
- Real-world Example:
sudo apt remove nano
- Explanation: This uninstalls the
nanopackage but may leave behind system-wide configuration files.
System Monitoring
Command:
btop- Purpose: An interactive, modern, and easy-to-read system resource monitor.
- Real-world Example:
btop
- Explanation: This is a vast improvement over
top. It shows CPU, memory, disk, and network usage in a clean interface. Use your arrow keys or mouse to navigate. Pressqto quit.
Command:
df -h- Purpose: Shows Disk Free space.
- Real-world Example:
df -h - Explanation: The
-hflag makes the output human-readable (e.g., "50G" instead of "52428800"). This is how you check if your drives are getting full.
Command:
free -m- Purpose: Shows free and used memory (RAM).
- Real-world Example:
free -m - Explanation: The
-mflag shows the values in megabytes. This is a quick check on your system's memory usage.
Networking
Command:
ip addr show- Purpose: Shows all network interfaces and their IP addresses.
- Real-world Example:
ip addr show
- Explanation: This is the modern replacement for
ifconfig. You use this to find your server's IP address (e.g.,inet 192.168.1.10/24).
Command:
curl <url>Purpose: cURL is a versatile tool to transfer data from or to a server.
Real-world Example 1 (Fetching Data):
curl https://api.coindesk.com/v1/bpi/currentprice/BTC.jsonExplanation: This fetches the content of that URL (a JSON file with the Bitcoin price) and prints it directly to your terminal.
Real-world Example 2 (Downloading a File):
curl -LO https://releases.ubuntu.com/noble/SHA256SUMS
Explanation: This is how we download files from the command line. The
-Lflag follows any server redirects, and the-Oflag saves the file with its original name from the URL.
Command:
ssh <user@host>- Purpose: Connects to a remote server using the Secure SHell protocol.
- Real-world Example:
ssh bitcoin@192.168.1.10 - Explanation: This securely connects you to the server at
192.168.1.10, logging in as thebitcoinuser. This is the primary way you will manage your server.
Service Management (systemd)
Your server applications (like bitcoind) run as services. systemd is the tool you use to control them.
Command:
sudo systemctl status <service>- Purpose: Checks the status of a service.
- Real-world Example:
sudo systemctl status sshd
- Explanation: This is your primary troubleshooting command. It will tell you if the SSH service is "active (running)" or "failed" and show you the last few log lines related to it.
Command:
sudo systemctl start <service>- Purpose: Starts a service.
- Real-world Example:
sudo systemctl start bitcoind
- Explanation: This will start the
bitcoindservice (assuming you have it installed).
Command:
sudo systemctl stop <service>- Purpose: Stops a service.
- Real-world Example:
sudo systemctl stop bitcoind
- Explanation: This safely stops the
bitcoindservice.
Command:
sudo systemctl reload <service>- Purpose: Reloads a service's configuration files without stopping it.
- Real-world Example:
sudo systemctl reload sshd
- Explanation: After you edit the
/etc/ssh/sshd_configfile, you must run this to apply your changes without disconnecting your active SSH session.
Command:
journalctl -u <unit_name> -f- Purpose: Shows the logs for only one specific service and follows them in real-time.
- Real-world Example:
journalctl -u bitcoind -f
- Explanation: This is the modern, professional way to watch a specific service's logs live. It's far better than
tail -fbecause it only shows you logs frombitcoind. PressCtrl+Cto stop.
The Pipe
The pipe (|) is a fundamental concept. It takes the output of the command on its left and "pipes" it directly as the input for the command on its right. This lets you chain simple tools together to perform complex tasks.
Real-world Example:
ls -la /etc | less
- What it does:
ls -la /etcproduces a very long list of all files in the/etcdirectory. On its own, it would fly past your screen. - How the pipe helps: We pipe that long list into the
lesscommand.lessis a pager that lets you scroll up and down through the list. This is the standard way to read long output.
Another Example:
journalctl -u sshd | grep "Failed password"
- What it does:
journalctl -u sshddumps all logs for the SSH service, which could be thousands of lines. - How the pipe helps: We pipe that log output to
grep, which then filters the text, showing you only the lines that contain the exact phrase "Failed password." This is how you find specific errors in a massive log file.