Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Server Command Line Interface: Mastering the Terminal

In this chapter

  • Understand the difference between TTY sessions and graphical terminal emulators
  • Learn the core commands for moving, inspecting, finding, copying, and deleting files
  • Use permissions, links, and disk-usage tools with better judgment
  • Build a mental map of the Linux filesystem layout

The terminal is one of the biggest advantages Linux gives you. It is fast, scriptable, dependable, and available even when a desktop session is broken. You do not need to become a shell expert on day one, but you do need to become comfortable with the commands you will use constantly.

Pro Tip: If the graphical interface stops responding, press Ctrl + Alt + F2 or Ctrl + Alt + F3 to reach a text console. On many systems, Ctrl + Alt + F1 through Ctrl + Alt + F6 switch between TTY sessions.

Terminal Safety First

Before you run any command copied from the internet, verify what it does and what path it targets.

Commands that deserve extra caution:

  • rm -rf
  • dd
  • chmod -R
  • chown -R

A safe habit is to preview paths first:

ls /path/you/plan/to/change

Then run the command only when the path is confirmed.

Types of Terminals

  • TTY: A text console tied directly to the system. This is useful for recovery, maintenance, and situations where the desktop is unavailable.
  • GUI terminal: A terminal emulator inside your desktop environment, such as GNOME Terminal, Konsole, or Kitty.

GUI terminals are usually opened from the application launcher, with Ctrl + Alt + T, or with a window-manager shortcut such as Super + Enter. TTY sessions are more limited, but they are dependable when everything else fails.

  • GNOME Terminal: A solid default for GNOME users with tabs, profiles, and predictable behavior.
  • Konsole: Excellent for KDE users and one of the best choices if you want split views and deep customization.
  • Alacritty: Fast and minimal, especially good if you prefer keyboard-driven workflows.
  • Kitty: Feature-rich and powerful, with strong performance and good scripting options.
  • Terminator: Useful if you like managing several panes in a single terminal window.

Core File and Directory Commands

Move Around the Filesystem

  • pwd: Print the current working directory.
  • cd ..: Move up one directory.
  • cd name: Move into a child directory.
  • cd /: Jump to the root of the filesystem.
  • cd ~: Return to your home directory.
  • zoxide: A faster way to jump to frequently used locations based on your command history.

Inspect Files and Folders

  • ls -a: Show all files, including hidden ones.
  • ls -l: Show permissions, owners, sizes, and timestamps.
  • tree -L 2: Display the directory structure up to two levels deep.
  • stat file: Show detailed metadata for a file or directory.

Find Things Quickly

  • find /path -name "filename": Search for a file by name.
  • find /path -type d -name "dirname": Search for directories by name.
  • fd pattern: A simpler and usually faster alternative to find.
  • locate filename: Search a prebuilt file index.
  • updatedb: Refresh the locate database when needed.

Copy, Move, and Delete with Care

Copy and Move

  • cp -r source destination: Copy directories recursively.
  • rsync -av source destination: Copy or synchronize large directory trees more efficiently.
  • mv file1.txt file2.txt: Rename a file.
  • mv /path/to/file /new/path/: Move a file or directory.

Delete

  • rmdir dirname: Remove an empty directory.
  • rm -rf path: Recursively and forcefully delete files or directories.
  • trash-cli: Move files to the desktop trash instead of deleting them permanently.

Warning: rm -rf is one of the fastest ways to destroy data on Linux. Use it only when you are certain the target path is correct.

If the deletion target is user data, prefer trash workflows first.

trash-put important-file.txt
  • ln -s /path/to/original /path/to/link: Create a symbolic link.
  • ln /path/to/original /path/to/link: Create a hard link.

Permissions

  • chmod 755 file: Set common executable permissions for scripts and directories.
  • chmod +x script.sh: Mark a script as executable.

Ownership

  • chown user:group file: Change the owner and group of a file.
  • chown -R user:group /path/to/directory: Change ownership recursively.

These commands matter because Linux treats executability, ownership, and file permissions as core security boundaries rather than optional metadata.

Reading Common Error Messages

Three terminal errors show up constantly for new users:

  • command not found: usually a typo or missing package.
  • permission denied: wrong user, wrong mode, or missing sudo.
  • no such file or directory: invalid path or wrong working directory.

Check command spelling, run pwd, and inspect the target with ls -l before escalating to bigger changes.

Built-In Help You Should Use Daily

Linux has excellent built-in documentation. Use this before searching random forums.

  • command --help: quick usage and flags
  • man command: full manual page
  • info command: deeper GNU documentation for some tools
  • tldr command: practical short examples (if installed)

Example workflow:

man rsync
rsync --help

Learning to read man pages is one of the fastest ways to become self-sufficient.

Measuring Disk Usage

  • du -h: Show the size of files and directories.
  • du -sh /path/to/directory: Show the total size of one directory.
  • df -h: Show free and used disk space by filesystem.
  • df -i: Show inode usage instead of storage usage.

Use du when you want to know what is consuming space inside a directory tree. Use df when you want to know whether the underlying filesystem itself is full.

Directory Layout and Filesystem Overview

  • /: The root of the filesystem.
  • /bin: Essential executable commands.
  • /boot: Bootloader files and kernel-related data.
  • /dev: Device files that represent hardware and virtual devices.
  • /etc: System-wide configuration files.
  • /home: User home directories and most personal data.
  • /media: Mount points for removable media.
  • /mnt: Temporary mount points.
  • /opt: Optional third-party software.
  • /root: The root user’s home directory.
  • /tmp: Temporary files.
  • /usr: Shared applications, libraries, and system resources.
  • /var: Logs, caches, and other changing application data.

Most of your day-to-day work happens in /home. Spend time learning /etc, /var, and /usr, but edit them deliberately rather than casually.

First Shell Customization

A few small shell changes improve safety and usability right away.

Example aliases for Bash or Zsh:

alias ll='ls -lah'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

Add them to your shell configuration file, then reload it:

source ~/.bashrc

For Zsh users:

source ~/.zshrc

Command History and Verification Habits

Use shell history to avoid repeating mistakes and to speed up safe workflows.

  • history: list recent commands
  • Ctrl + R: reverse search previous commands
  • !!: rerun the previous command (use carefully)
  • sudo !!: rerun the previous command with sudo

When testing potentially risky commands, echo first:

echo rm -rf /path/example

If the printed command is not exactly what you intended, stop and correct it.

Key takeaways

  • The terminal is a primary Linux tool, not a last resort.
  • Group commands by job: navigate, inspect, search, copy, delete, and measure.
  • Treat `rm -rf`, `chmod`, and `chown` as precision tools.
  • Understanding the top-level directory layout makes every later chapter easier.
Last change: