Table of Contents

    Terminal / Command Line Basics

    Programming Tools

    Terminal / Command Line Basics

    Learn what the terminal and command line are, why programmers use them, and how to perform basic operations such as navigation, file handling, running programs, and checking installed tools.

    What is a Terminal?

    A terminal is a text-based interface that allows users to communicate with a computer by typing commands. Instead of using only buttons, menus, and icons, users can type instructions directly to the operating system.

    In programming, the terminal is used to run programs, install packages, navigate folders, manage files, check versions of tools, and work with development environments.

    A terminal allows programmers to control the computer using typed commands instead of only using a graphical interface.

    The terminal is especially useful for developers because many programming tools, compilers, interpreters, package managers, and version control systems are commonly used through command-line commands.

    What is a Command Line?

    The command line is the place inside the terminal where the user types commands. It accepts typed instructions, sends them to the operating system or shell, and then displays the result.

    Simple Meaning
    User Types Command System Processes Command Output Appears

    For example, when a user types a command to list files, the operating system checks the current folder and shows the available files and directories.

    Terminal, Shell, and Command Line Difference

    Beginners often use the words terminal, shell, and command line as if they are the same. They are related, but they are not exactly the same.

    Term Meaning Example
    Terminal The application or window where commands are typed. Windows Terminal, macOS Terminal, Linux Terminal
    Shell The program that understands and executes commands. Bash, PowerShell, Zsh, Command Prompt
    Command Line The text input area where the user types commands. C:\Users\Student> or $

    Easy Real-Life Example

    Terminal as a Direct Assistant

    Imagine you have an assistant. Instead of manually doing every task yourself, you give direct instructions such as “open this folder,” “create a file,” or “copy this document.” The terminal works similarly. You type commands, and the computer performs the task.

    Why Programmers Use Terminal / Command Line

    Programmers use the terminal because it is fast, powerful, flexible, and widely used in real-world software development. Many development tasks are easier and quicker from the command line.

    Main Uses of Terminal in Programming

    • Running programs from the command line.
    • Compiling source code using compilers.
    • Checking installed versions of programming tools.
    • Creating, copying, moving, and deleting files or folders.
    • Installing packages and libraries.
    • Using Git and GitHub commands.
    • Running development servers for web applications.
    • Managing projects faster than using only a graphical interface.
    • Working with servers, cloud platforms, and deployment tools.

    Common Terminal Applications

    Different operating systems provide different terminal or command-line tools. The commands may vary depending on the operating system and shell being used.

    Operating System Common Terminal / Shell Common Use
    Windows Command Prompt, PowerShell, Windows Terminal Running commands, scripts, development tools, and system utilities.
    macOS Terminal, Zsh Running Unix-like commands, development tools, and scripts.
    Linux Terminal, Bash System administration, programming, server management, and automation.

    Prerequisites Before Using Terminal

    Before students start using the terminal, they should understand a few basic requirements. These prerequisites help them avoid confusion while running commands.

    Basic Prerequisites

    • A computer with Windows, macOS, or Linux operating system.
    • Basic understanding of files and folders.
    • Ability to open Command Prompt, PowerShell, Terminal, or Windows Terminal.
    • For programming practice, required tools such as Python, Java, Node.js, PHP, or .NET should be installed when needed.
    • For project work, a code editor such as Visual Studio Code is helpful.
    • For Git practice, Git should be installed on the computer.

    How to Open Terminal

    The way to open the terminal depends on the operating system. Students should first learn how to open the command-line tool on their own computer.

    System How to Open
    Windows Search for Command Prompt, PowerShell, or Windows Terminal from the Start menu.
    macOS Open Spotlight Search, type Terminal, and open the Terminal app.
    Linux Open Terminal from the application menu or use the keyboard shortcut supported by the desktop environment.

    Understanding Current Directory

    A directory means a folder. When you open the terminal, you are always located inside some folder. This folder is called the current working directory.

    Many commands work based on the current directory. For example, if you create a file using the terminal, it will usually be created inside the current folder unless you specify another location.

    Important: Before creating, moving, copying, or deleting files, always check which directory you are currently inside.

    Basic Navigation Commands

    Navigation commands help users move between folders and understand where they are inside the file system.

    Command Meaning Purpose
    pwd Print Working Directory Shows the current directory path.
    ls List Shows files and folders in the current directory.
    cd Change Directory Moves from one folder to another.
    cd .. Go One Level Up Moves to the parent directory.
    mkdir Make Directory Creates a new folder.

    Linux / macOS Navigation Examples

    pwd
    ls
    cd Documents
    cd ..
    mkdir practice

    Windows Command Prompt Navigation Examples

    cd
    dir
    cd Documents
    cd ..
    mkdir practice

    Windows PowerShell Navigation Examples

    pwd
    ls
    cd Documents
    cd ..
    mkdir practice
    Note: In Windows Command Prompt, dir is commonly used to list files and folders. In Linux, macOS, and PowerShell, ls is commonly used.

    Basic File Commands

    File commands help users create, view, copy, rename, move, and delete files from the terminal.

    Command Purpose Example
    touch Creates an empty file in Linux/macOS. touch app.txt
    cat Displays file content. cat app.txt
    cp Copies a file. cp old.txt new.txt
    mv Moves or renames a file. mv old.txt new.txt
    rm Deletes a file in Linux/macOS. rm app.txt
    del Deletes a file in Windows Command Prompt. del app.txt

    Linux / macOS File Examples

    touch notes.txt
    cat notes.txt
    cp notes.txt backup.txt
    mv backup.txt old-notes.txt
    rm old-notes.txt

    Windows Command Prompt File Examples

    echo Hello > notes.txt
    type notes.txt
    copy notes.txt backup.txt
    ren backup.txt old-notes.txt
    del old-notes.txt

    Absolute Path vs Relative Path

    A path tells the computer where a file or folder is located. There are two common types of paths: absolute path and relative path.

    Relative Path Absolute Path
    Starts from the current directory. Starts from the root location or full drive location.
    Shorter and easier when working inside a project folder. Longer but gives the complete location of a file or folder.
    cd images cd /home/student/project/images
    cd css cd C:\Users\Student\project\css

    Running Programs from Terminal

    One of the most important uses of the terminal in programming is running source code or compiled programs. Different languages use different commands.

    Language / Tool Command Purpose
    Python python app.py Runs a Python file.
    Java javac Main.java and java Main Compiles and runs a Java program.
    JavaScript / Node.js node app.js Runs JavaScript outside the browser.
    PHP php index.php Runs a PHP file from the terminal.
    .NET dotnet run Runs a .NET project.

    Python Example

    print("Hello from Python terminal!")
    python app.py

    Java Example

    public class Main {
        public static void main(String[] args) {
            System.out.println("Hello from Java terminal!");
        }
    }
    javac Main.java
    java Main

    JavaScript Example

    console.log("Hello from Node.js terminal!");
    node app.js

    Checking Installed Tool Versions

    Developers often use terminal commands to check whether programming tools are installed correctly. Version commands are useful for troubleshooting and setup verification.

    python --version
    node --version
    npm --version
    java -version
    javac -version
    php --version
    dotnet --version
    git --version
    Good Practice Always check the installed version of a programming language or tool before starting a project. This helps avoid version mismatch errors.

    Package Managers and Terminal

    A package manager is a tool used to install, update, and manage external libraries or dependencies. Many package managers are used from the terminal.

    Package Manager Used For Example Command
    npm JavaScript / Node.js packages npm install package-name
    pip Python packages pip install package-name
    composer PHP packages composer install
    dotnet .NET packages and projects dotnet add package PackageName

    Git Commands from Terminal

    Git is commonly used from the terminal to track code changes and work with repositories. A beginner should know a few basic Git commands.

    git --version
    git init
    git status
    git add .
    git commit -m "Initial commit"
    git log
    Prerequisite: To use Git commands, Git must be installed on the computer.

    Input, Output, and Redirection

    The terminal can display output on the screen, accept input from the user, and redirect output into files.

    Symbol / Command Meaning Example
    > Writes output to a file and replaces old content. echo Hello > file.txt
    >> Adds output to the end of a file. echo Hello >> file.txt
    | Sends output of one command into another command. cat file.txt | more
    echo "Hello Student" > message.txt
    echo "Welcome to Programming" >> message.txt
    cat message.txt

    Command History and Shortcuts

    Most terminals remember previously typed commands. This helps users repeat or modify old commands without typing everything again.

    Useful Terminal Shortcuts

    • Use the Up Arrow key to view previous commands.
    • Use the Down Arrow key to move forward in command history.
    • Use Tab to autocomplete file or folder names in many terminals.
    • Use Ctrl + C to stop a running command in many terminal environments.
    • Use Ctrl + L to clear the terminal screen in many shell environments.

    Common Beginner Mistakes

    Common Mistakes

    • Typing commands in the wrong directory.
    • Confusing files and folders.
    • Using Linux commands directly in Windows Command Prompt.
    • Forgetting to install the required programming language.
    • Deleting files without checking the path.
    • Ignoring error messages instead of reading them carefully.

    Better Habits

    • Use pwd or cd to confirm the current location.
    • Use ls or dir before deleting anything.
    • Practice commands in a test folder first.
    • Check tool versions before running code.
    • Read terminal errors line by line.
    • Keep project folders organized.

    Understanding Terminal Error Messages

    Terminal errors are not always bad. They help programmers understand what went wrong. A good programmer learns to read error messages carefully.

    Error Message Possible Meaning What to Check
    command not found The command or tool is not installed or not added to PATH. Check installation and environment variables.
    No such file or directory The file or folder name/path is incorrect. Check spelling and current directory.
    Permission denied The user does not have permission to access or modify something. Check file permissions or run with proper access.
    Syntax error The command or code has incorrect syntax. Check command format or program syntax.

    Safety Tips While Using Terminal

    The terminal is powerful. A wrong command can delete files or change important settings. Beginners should practice carefully.

    Terminal Safety Rules

    • Do not run commands copied from unknown sources without understanding them.
    • Be careful with delete commands such as rm, del, and rmdir.
    • Practice inside a separate test folder.
    • Read command output and error messages carefully.
    • Do not use administrator or root permissions unless required.
    • Keep backups of important files before experimenting.

    Practice Activity: Create and Run a Simple Project Folder

    This beginner-friendly activity helps students practice navigation, folder creation, file creation, and running a basic program.

    Step 1: Create a Practice Folder

    mkdir terminal-practice
    cd terminal-practice

    Step 2: Create a Python File

    Create a file named app.py using your code editor, then add the following code:

    print("Terminal practice completed successfully!")

    Step 3: Run the File

    python app.py

    Expected Output

    Terminal practice completed successfully!

    Mini Quiz

    1

    What is the terminal?

    The terminal is a text-based interface used to interact with the computer by typing commands.

    2

    Which command shows the current directory in Linux/macOS?

    The pwd command shows the current working directory.

    3

    Which command is used to change directory?

    The cd command is used to change from one directory to another.

    4

    Which command lists files in Windows Command Prompt?

    The dir command lists files and folders in Windows Command Prompt.

    5

    Why should programmers learn command line basics?

    Programmers should learn command line basics because many development tasks such as running programs, installing packages, using Git, and managing files are commonly performed through the terminal.

    Interview Questions on Terminal / Command Line Basics

    1

    What is a command line interface?

    A command line interface is a text-based interface where users type commands to interact with the operating system or software tools.

    2

    What is the difference between GUI and CLI?

    GUI uses graphical elements such as buttons, icons, and menus, while CLI uses typed commands to perform operations.

    3

    What is the use of the cd command?

    The cd command is used to change the current working directory.

    4

    What is the use of the mkdir command?

    The mkdir command is used to create a new directory or folder.

    5

    What does “command not found” mean?

    It usually means the command is incorrect, the tool is not installed, or the tool is not available in the system PATH.

    Quick Summary

    Concept Meaning
    Terminal A text-based application used to type commands.
    Command Line The area where commands are entered.
    Shell The program that interprets and executes commands.
    pwd Shows the current directory in Linux/macOS and PowerShell.
    ls Lists files and folders in Linux/macOS and PowerShell.
    dir Lists files and folders in Windows Command Prompt.
    cd Changes the current directory.
    mkdir Creates a new directory.

    Final Takeaway

    Terminal / Command Line Basics are essential for every programmer. They help you navigate folders, manage files, run programs, install packages, use Git, troubleshoot errors, and work more efficiently like a real developer.