Linux Terminal for Beginners: The Most Important Commands for Your Server

Learn the most important Linux terminal commands for your server. A beginner-friendly guide to navigating, managing files, viewing system information, and more.

Linux Terminal for Beginners: The Most Important Commands for Your Server hero image

If you run your own Linux server, whether it’s a VPS (Virtual Private Server) or a home server, you usually can’t avoid the terminal. At first, it might seem a bit intimidating – a black box with a blinking cursor waiting for your input. But don’t worry, it’s not as complicated as it looks! The terminal, also called the command line or shell, is an incredibly powerful tool to control your server directly and efficiently.

Today, I’ll show you the most important Linux commands that you, as a self-hoster, need to know to navigate your server, manage files, and perform basic tasks.

Establishing a Connection

Before we start, you first need to connect to your server. This is usually done via SSH (Secure Shell). You’ll need:

  1. The IP address of your server.
  2. Your username on the server.
  3. Your password or (better) an SSH key.

On Windows, you can use tools like PuTTY or the integrated OpenSSH in Terminal/PowerShell in Windows 10/11. On macOS and Linux, the SSH client is available directly in the terminal.

ssh YOUR_USERNAME@YOUR_SERVER_IP

Enter your password when prompted, and you’re in!

1. Navigating the File System: Where am I and where do I want to go?

First things first: How do we move around in the file system? Think of the file system as a system of folders (directories) and files.

  • pwd (Print Working Directory): Where am I currently? This command shows you the full path of the directory you are currently in.

    pwd

    Example output: /home/YOUR_USERNAME

  • ls (List): What’s in here? Lists the content of the current directory – i.e., which files and folders are located here.

    ls

    ls can be supplemented with additional parameters (options). Useful options include:

    • ls -l: Shows a detailed list with permissions, owner, size, and modification date. The l stands for “long”.
    • ls -lh: Like -l, but with “human-readable” file sizes (e.g., “1.5K” instead of “1536”).
    • ls -a: Also lists hidden files and folders (those starting with a dot, e.g., .bashrc). Here you’ll also see . (current directory) and .. (parent directory).

    You can also give ls a path to display the content of another folder:

    ls /var/log # Shows the content of /var/log
    ls /        # Shows the content of the root directory
  • Help! man (Manual): You don’t have to memorize all commands and options! For common commands, there are built-in manuals, the “man pages”.

    man ls

    This shows you everything about the ls command. You navigate with the arrow keys, and press Q to exit the view.

  • cd (Change Directory): Change directory With cd, you change the directory.

    cd /var/www/html  # Changes to the directory /var/www/html
    cd ..             # Moves one level up (to the parent directory)
    cd                # Without arguments, changes back to your home directory
    cd ~              # Also to the home directory
    cd -              # Changes to the previous directory

    Your terminal often shows you which directory you are currently in (e.g., YOUR_USERNAME@SERVERNAME:~/docker$). The tilde (~) stands for your home directory.

  • Tab Completion: Your Best Friend! An important tip: If you start typing a path or file name and then press the Tab key, the shell tries to complete the name. If you press Tab twice, possible completions are displayed. This saves an enormous amount of time and avoids typos!

    cd AdGu  # Type "AdGu" and press Tab -> becomes "cd AdGuardHome/" (if unique)
  • clear: Clear screen Clears the current screen content of the terminal.

2. Creating and Managing Files and Folders

Now that we can navigate, we also want to create and modify things.

  • mkdir (Make Directory): Create new folders

    mkdir my_project

    This creates a folder named my_project in the current directory. If you want to create a whole chain of folders that don’t exist yet (e.g., my_project/assets/images), you can do this with the -p (parents) option:

    mkdir -p my_project/assets/images
  • touch: Create empty files or update timestamps

    touch important_note.txt

    Creates an empty file named important_note.txt. If the file already exists, its timestamp is updated.

  • cp (Copy): Copy files and folders The command is cp SOURCE DESTINATION.

    cp important_note.txt backup_note.txt   # Copies the file
    cp important_note.txt my_project/      # Copies the file into the my_project folder

    To copy entire folders with content, you need the -r (recursive) option:

    cp -r my_project /tmp/project_backup
  • mv (Move): Move or rename files and folders Similar to cp, but the source is removed.

    mv important_note.txt just_a_note.txt             # Renames the file
    mv just_a_note.txt my_project/                # Moves the file into the folder
    mv my_project/important_note_2.txt .        # Moves file from my_project to the current dir (.)
  • rm (Remove): Delete files and folders Be careful with rm! Deleted files are usually gone for good.

    rm just_a_note.txt  # Deletes the file

    To delete a folder, you again need the -r (recursive) option. If the folder is not empty, a prompt will often appear.

    rm -r my_project # Deletes the my_project folder and its content

    Sometimes, prompts appear during deletion. These can be suppressed with -f (force). EXTREMELY DANGEROUS: rm -rf PATH recursively deletes everything in the specified path without prompting. A wrong rm -rf / can delete your entire system! Use -f only when absolutely necessary and you know exactly what you are doing.

3. Viewing and Editing Text Files

To view and edit configuration files or scripts, you need a text editor.

  • cat (Concatenate): Display content of a file Displays the entire content of a file directly in the terminal. Practical for short files.

    cat testfile.txt
  • less: Display content of a file page by page For longer files, less is better. You can scroll with the arrow keys or Page Up/Down. With / you can search for text, with N jump to the next match. Press Q to exit less.

    less /var/log/syslog
  • nano: Simple text editor nano is a beginner-friendly editor that runs in the terminal. The most important commands are displayed at the bottom of the screen (e.g., Ctrl+O to save, Ctrl+X to exit).

    nano my_config.conf
  • vim (or vi): Powerful, but takes getting used to vim is pre-installed on almost every Linux system. It has a steeper learning curve but is extremely efficient once mastered.

    vim testfile.txt

    The most important vim basics:

    • Press I to switch to Insert Mode (INSERT) and type text.
    • Press Esc to exit Insert Mode and enter Command Mode.
    • In Command Mode:
      • :w saves the file (write).
      • :q quits Vim (quit).
      • :wq or :x saves and quits.
      • :q! quits without saving (discards changes).

4. Understanding and Changing Permissions

Every file and folder in Linux has permissions that define who can do what with it.

  • Displaying permissions with ls -l At the beginning of each line of ls -l, you’ll see something like drwxr-xr-x or -rw-r--r--.

    • The first character: d for Directory, - for a regular file.
    • The next nine characters are in groups of three: Owner, Group, Others.
    • r stands for Read permission.
    • w stands for Write permission.
    • x stands for Execute permission (for folders, this means you can enter them). Example: drwxr-xr-x
    • d: It’s a directory.
    • rwx (Owner): The owner can read, write, and execute.
    • r-x (Group): Members of the group can read and execute, but not write.
    • r-x (Others): All others can also read and execute.
  • chmod (Change Mode): Change permissions You can change permissions symbolically or numerically.

    • Symbolically:
      • u (user/owner), g (group), o (others), a (all).
      • + (add), - (remove), = (set exactly).
      chmod u+x my_script.sh   # Adds execute permission for the owner
      chmod g-w sensitive_file.txt # Removes write permission for the group
      chmod a+r important_info.txt # Gives read permission to all
      chmod go-rwx private_data  # Removes all permissions for group and others
    • Numerically (Octal): Each permission has a numerical value: r=4, w=2, x=1. Add the values for the desired permissions.
      • 7 (4+2+1) = rwx
      • 6 (4+2+0) = rw-
      • 5 (4+0+1) = r-x
      • 4 (4+0+0) = r-- The command is chmod OWNER_NUMBER GROUP_NUMBER OTHERS_NUMBER FILE/FOLDER.
      chmod 755 my_script.sh  # Owner: rwx, Group: r-x, Others: r-x
      chmod 600 private_keys # Owner: rw-, Group: ---, Others: ---

chmod Permissions Calculator

Owner

Group

Others

Octal:644

Symbolic:-rw-r--r--

Example: chmod 644 my_file.txt
ls -l Output: -rw-r--r-- 1 user group ... my_file.txt

  • chown (Change Owner): Change owner and group To change the owner and/or group of a file. Often requires sudo.
    sudo chown new_owner:new_group file.txt
    sudo chown YOUR_USERNAME:YOUR_USERNAME important_note.txt # Changes owner and group

5. Viewing and Killing Processes

Sometimes you need to see which programs (processes) are running on your server or kill a process that’s causing problems.

  • ps aux: Show all running processes Displays a detailed list of all processes. The output can be very long.

    ps aux
    # To search for a specific process (e.g., nginx):
    ps aux | grep nginx
  • top: Dynamic process view Shows a continuously updating list of processes, sorted by CPU usage. Press Q to exit top.

  • htop: More user-friendly alternative to top htop is colorful and offers more interaction options (e.g., select processes with arrow keys and send kill with F9). Often needs to be installed first: sudo apt install htop.

    htop

    Press Q (or F10) to exit htop.

  • kill: Kill processes If a process hangs, you can kill it with kill and its Process ID (PID – found with ps or htop, for example).

    # Find the PID of htop, e.g., 62434
    kill 62434

    By default, kill sends a TERM signal (15), telling the process to terminate cleanly. If that doesn’t help, you can send a KILL signal (9), which terminates the process immediately and “hard”:

    kill -9 PID_OF_THE_PROCESS # Use only in emergencies!

6. Network Basics

A few commands to check your network connection.

  • ip addr (or ifconfig on older systems): Show network configuration Displays your network interfaces and their IP addresses.

  • ping: Test reachability Tests if another host on the network or internet is reachable and measures the response time.

    ping google.com

    Press Ctrl+C to stop the ping.

  • curl: Transfer data from/to URLs curl is a versatile tool for transferring data with URLs. A simple application is downloading the HTML content of a webpage:

    curl https://deployn.de

    This displays the HTML source code of the page in the terminal.

7. System Information and Disk Space

Important commands to monitor the state of your system.

  • df -h (Disk Free): Show disk space usage Displays the usage of your hard drive partitions in human-readable format (-h).

    df -h
  • free -h: Show memory usage Displays the usage of your RAM and swap space.

  • journalctl: View system logs (systemd) On modern systems with systemd (like Ubuntu, Debian), journalctl is the central tool for viewing system logs.

    • journalctl -f: Shows logs live (“follow”). Press Ctrl+C to stop.
    • journalctl -u SERVICE_NAME: Shows logs for a specific service (e.g., sshd or nginx).
    • journalctl -xe: Shows the latest log entries with additional explanations for errors.
  • dmesg (Driver Messages): Show kernel messages Useful for diagnosing hardware problems or issues during system startup.

8. Installing and Managing Software (Package Manager)

To install, update, or remove software, you use a package manager. On Debian-based systems like Ubuntu, this is apt.

  • sudo apt update: Update package lists Downloads the latest information about available packages from the servers (repositories). Should be run before upgrade or install.

  • sudo apt upgrade: Upgrade installed packages Installs the latest versions of all packages already installed on your system. Confirm with Y when prompted.

  • sudo apt install PACKAGENAME: Install a new package

    sudo apt install htop tree mc  # Installs htop, tree, and Midnight Commander
  • sudo apt remove PACKAGENAME: Remove a package Uninstalls a package but often leaves configuration files behind.

  • sudo apt purge PACKAGENAME: Completely remove a package Uninstalls a package including its configuration files.

  • sudo apt autoremove: Remove no longer needed packages Removes dependencies that are no longer needed after uninstalling other packages.

  • apt search SEARCH_TERM: Search for packages Searches the available packages for a specific term.

9. Powerful Helpers: sudo, Pipes, and Redirection

  • sudo (Superuser Do): Execute commands with root privileges Many system commands require administrator rights (root privileges). sudo temporarily prepends root privileges to these commands. You will be asked for your user password.

  • | (Pipe): Chain outputs The pipe redirects the standard output of one command to the standard input of another command. Extremely useful!

    ps aux | grep sshd       # Shows only process lines containing "sshd"
    ls -l /etc | less       # Pipes the long list from /etc to `less` for scrolling
    journalctl -u nginx | grep "error" # Searches nginx logs for errors
  • > (Redirection): Write output to a file (overwrites!) Redirects the output of a command to a file. If the file exists, it will be overwritten.

    ls -l > filelist.txt # Writes the output of ls -l to filelist.txt
  • >> (Redirection): Append output to a file Redirects the output to a file. If the file exists, the new output will be appended to the end. If not, it will be created.

    echo "New log entry: $(date)" >> server.log # Appends a timestamp to server.log

Important Tips for Beginners

  • Tab Completion: Your best friend! Saves typing and avoids errors.
  • man Pages: Use man COMMAND to learn more about a command.
  • history: Shows you a list of your most recently entered commands. With !NUMBER you can re-execute a command from the history.
  • Ctrl+C: Cancels the currently running command.
  • Ctrl+R: Searches backward through your command history.
  • Small Steps: Especially at the beginning, try out commands and understand what they do before applying them to important data or system configurations.
  • Test Server: If possible, play around on a test server or a virtual machine before making changes to a production system.

Conclusion

That was a lot of basics! The terminal is an incredibly versatile and efficient tool once you’ve understood the fundamentals.

Share this post:

This website uses cookies. These are necessary for the functionality of the website. You can find more information in the privacy policy