pull down to refresh

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.
  • 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 -l flag gives a long list (showing permissions, owner, size). The -a flag 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/log directory. All commands you run next will be from this new location. (Use cd ~ to return to your home directory).
  • Command: mkdir <dirname>
    • Purpose: Make Directory.
    • Real-world Example:
      mkdir ~/projects
      
    • Explanation: This creates a new directory named projects inside 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.md inside the projects directory 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 projects folder 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.md file to README.md within the same directory. You also use mv to 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! rm is permanent and has no "undo" or "recycle bin." (To delete a directory, you use rm -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 q to 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+C to 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 syslog file 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 bitcoin user. 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. (Type exit to 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 nano package 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. Press q to quit.
  • Command: df -h
    • Purpose: Shows Disk Free space.
    • Real-world Example:
      df -h
      
    • Explanation: The -h flag 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 -m flag 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.json
      
    • Explanation: 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 -L flag follows any server redirects, and the -O flag 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 the bitcoin user. 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 bitcoind service (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 bitcoind service.
  • 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_config file, 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 -f because it only shows you logs from bitcoind. Press Ctrl+C to 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 /etc produces a very long list of all files in the /etc directory. On its own, it would fly past your screen.
  • How the pipe helps: We pipe that long list into the less command. less is 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 sshd dumps 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.
reply
Lol.
reply
Would be great to add cheat sheet image at the end, so we can print it.
reply
Can't edit an article past 10 minutes. Why not copy text to a document?
reply
Too much extra words for cheat sheet. We need something fancy, e.g.:
or
p.s. your article is great, and when we read it we need a list of all commands. If I forget how to use this tye command I'll get back to your article.
reply
0 sats \ 0 replies \ @OT 15h
Bookmarked!
I always have to look up commands when I get stuck.
One that I always stumble on is just trying to open an app. Like with Sparrow wallet there's a guide to download and pgp verify but nothing to actually open it (double clicking on the package doesn't work). I didn't see it in your list, it's something like dpkg -i
reply