Developer Guides

Beginner's Guide to Linux Terminal Basics

Learn the fundamentals of using the Linux terminal, including navigation, commands, and shortcuts, with this beginner-friendly guide.

4 min read

Learn the fundamentals of using the Linux terminal, including navigation, commands, and shortcuts, with this beginner-friendly guide. By following the steps below, you'll master essential commands like ls, cd, cat, grep, and understand navigation, file management, and process control in Linux.

Prerequisites for Getting Started

To start, ensure you have access to a Linux environment (physical machine, virtual machine, or WSL). You'll also need a terminal emulator such as Bash or Zsh to input commands.

prerequisites

  • Access to a Linux environment such as:
    • A Linux desktop or laptop.
    • A virtual machine running Linux.
    • Windows Subsystem for Linux (WSL).
    • SSH access to a Linux server.
  • Installed terminal emulator (e.g., Bash, Zsh, or equivalent).
  • Basic understanding of keyboard navigation.

Basic Navigation Commands

Get started with Linux terminal navigation by mastering the following commands.

steps

  1. Print the current working directory using:

    bash
    pwd

    This shows where you are in the file system.

  2. List the files and directories in the current directory:

    bash
    ls

    Add -l for detailed information or -a to include hidden files:

    bash
    ls -la
  3. Navigate to a directory with:

    bash
    cd directoryname

    Move up one level:

    bash
    cd ..

    Return to the home directory:

    bash
    cd ~
  4. Clear the terminal screen:

    bash
    clear

File Management Essentials

Learn to create and manage files and folders effectively.

steps

  1. Create a new file:

    bash
    touch filename
  2. Display file content:

    bash
    cat filename
  3. Copy a file:

    bash
    cp source destination
  4. Move or rename a file:

    bash
    mv source destination
  5. Remove a file:

    bash
    rm filename
  6. Create a new directory:

    bash
    mkdir directoryname
  7. Delete a directory and its content:

    bash
    rm -r directoryname

Using Editors for File Management

Directly edit files within the terminal using vim or nano. Both tools allow text editing, but their usage differs.

steps

  1. Open a file in vim:

    bash
    vim filename
    • Press i to enter INSERT mode.
    • Use Esc followed by :wq to save and quit.
  2. Open a file in nano:

    bash
    nano filename
    • Use Ctrl+O to save and Ctrl+X to exit.
  3. Tips:

    • Vim requires a learning curve but is powerful for advanced users.
    • Nano is more beginner-friendly with instructions displayed at the bottom.

Managing Permissions

Modify file and directory permissions as needed.

steps

  1. Check file permissions using:

    bash
    ls -l
  2. Change permissions with chmod:

    bash
    chmod 777 filename

    Replace 777 to control read, write, execute permissions for owner, group, and others.

  3. Change file ownership:

    bash
    sudo chown user:group filename
  4. Use sudo to run commands with superuser privileges:

    bash
    sudo command

Using Processes and Commands Efficiently

Manage processes and make better use of the terminal through the following commands.

steps

  1. List active processes:

    bash
    ps aux
  2. Kill a process by ID:

    bash
    kill PID
  3. Suspend a process with Ctrl+Z and bring it to the foreground:

    bash
    fg
  4. Redirect command outputs: Standard output:

    bash
    command > file.txt

    Append to an existing file:

    bash
    command >> file.txt

    Redirect errors:

    bash
    command 2> error.log

Additional Concepts and Utilities

Expand your knowledge with these advanced but helpful commands.

steps

  1. Set environment variables:

    bash
    export VAR=value

    Access the variable:

    bash
    echo $VAR
  2. Inspect and mount block devices:

    bash
    lsblk
    mount /dev/device_name /mnt/mount_point
  3. Unmount devices:

    bash
    umount /mnt/mount_point
  4. Redirect unwanted output to null:

    bash
    command > /dev/null

FAQ

What is the Linux terminal used for?

The Linux terminal allows users to interact directly with the operating system through text-based commands to perform tasks such as file management, software installation, and process control.

What's the difference between Ctrl+C and Ctrl+Shift+C?
  • Ctrl+C interrupts a running command or process in the terminal.
  • Ctrl+Shift+C is used to copy highlighted text from the terminal.
How do I check my current directory in Linux?

Use the pwd command to display your current working directory.

How can I see file permissions in Linux?

Run ls -l to view detailed file information, including the permissions.


Official reference: GNU Bash manual.