How to Open and Use the Terminal in Linux and macOS

Summary:
Learn the basics of using Terminal for shell scripting.


The terminal is a powerful tool that gives users direct access to their computer’s underlying operating system, allowing for efficient command-line control, file management, and shell scripting. Whether you are a beginner seeking to automate tasks, troubleshoot issues, or simply explore deeper functionality in Linux or macOS, mastering the basics of the Terminal is essential. This guide will show you how to open, navigate, and start using the Terminal for shell scripting.

What is the Terminal?

The Terminal—also known as the command line, console, or shell—offers a text-based interface to interact with your system. Unlike graphical user interfaces (GUIs), commands in the Terminal are issued with your keyboard, providing speed and precise control.

In both Linux and macOS, the Terminal typically runs a shell program like bash (Bourne Again SHell) or zsh (Z shell), allowing you to execute commands and scripts.


How to Open the Terminal

On Linux

Most Linux distributions include Terminal by default. Here's how to open it:

  • Via Application Menu:

    1. Click the application menu (might be labeled “Activities”, “Applications”, etc.).
    2. Search for “Terminal”.
    3. Click on the Terminal icon to open it.
  • Keyboard Shortcut:
    Most Linux desktops support the shortcut Ctrl + Alt + T.

  • Alternative:
    Right-click on the desktop or inside a file folder and select "Open Terminal here" (if available).

On macOS

Every Mac includes the Terminal app. Here’s how to access it:

  • Using Spotlight Search:

    1. Press Cmd + Space to open Spotlight.
    2. Type Terminal and press Enter.
  • Via Finder:

    1. Open Finder.
    2. Go to Applications > Utilities.
    3. Double-click Terminal.app.

Terminal Basics: Understanding the Prompt

Once you open the Terminal, you’ll see a prompt. It may look something like this:

user@hostname:~$

or on macOS:

yourname@MacBook ~ %

The prompt indicates the shell is ready to accept commands.


Common Terminal Commands

Below are a few fundamental commands for navigating and managing files.

Command Description
ls List files and directories
cd directory Change directory
pwd Print working directory
mkdir myfolder Create new directory
touch file.txt Create new file
cp src dst Copy files/directories
mv src dst Move/rename files/directories
rm file.txt Remove file
rm -r folder Remove folder and contents
cat file.txt View file contents

Try entering a few of these commands to get comfortable.


Your First Shell Script

A shell script is a file that contains a series of commands for the shell to execute. Let’s create and run a simple script.

  1. Open Terminal.

  2. Create a new script file:

    nano hello.sh
    
  3. Type your script:

    #!/bin/bash
    echo "Hello, world!"
    
  4. Save and exit:

    • Press Ctrl + O (write out), Enter to save.
    • Press Ctrl + X to exit nano.
  5. Make the script executable:

    chmod +x hello.sh
    
  6. Run your script:

    ./hello.sh
    

You should see:

Hello, world!

Tips for Using Terminal Effectively

  • Tab completion: Start typing a command or filename and press Tab to auto-complete.
  • Command history: Use the up/down arrow keys to scroll through previous commands.
  • Manual pages: Get help on commands with man <command>, e.g., man ls.
  • Clear the screen: Type clear or press Ctrl + L.

Conclusion

Learning to open and use the Terminal on Linux and macOS is a foundational skill for any computer user, especially those interested in shell scripting and system administration. By mastering basic commands and scripts, you can unlock unparalleled control over your system—boosting productivity and expanding your computing capabilities. Start exploring, experiment with commands, and soon the Terminal will become an indispensable tool in your workflow.


Ready to go further? In future posts, we'll dive deeper into shell scripting, automation, and advanced Terminal tools!