Skip to main content

Command Line Interface (CLI) Basics

Most people interact with computers using a GUI (Graphical User Interface)โ€”clicking icons, dragging folders, and using menus. However, developers use the CLI.

The CLI allows you to talk directly to your computer using text commands. It is the primary tool for running servers, installing packages, and managing Git.

1. Why Learn the CLI?โ€‹

At CodeHarborHub, we teach the terminal early because:

  1. Speed: Typing mkdir project is faster than right-clicking, selecting "New Folder," and renaming it.
  2. Automation: You can run complex sequences of tasks with a single script.
  3. Remote Power: Most web servers (like those running your website) don't have a screen or a mouseโ€”you must use the CLI to manage them.

2. Essential Commandsโ€‹

Think of these as your "Digital Survival Kit." Open your terminal (or the integrated terminal in VS Code) and try these:

CommandActionReal-world Analogy
pwdPrint Working Directory"Where am I right now?"
lsList Files"Show me what's in this folder."
cdChange Directory"Open this folder."
mkdirMake Directory"Create a new empty folder."
touchCreate File"Create a new empty file."
rmRemove"Delete this file (Be careful!)"

3. Navigation Masteryโ€‹

Moving around your computer via text takes a little practice. Here is how you "walk" through your folders:

# Go into a folder named 'projects'
cd projects

# Go back up one level (to the parent folder)
cd ..

# Go straight to your user's Home folder
cd ~

# Clear the screen if it gets too messy
clear

4. Useful Shortcutsโ€‹

Professional developers rarely type every single letter. Use these "Power Moves" to work faster:

  • Tab Completion: Type the first few letters of a file name and hit Tab. The terminal will finish the word for you!
  • Up/Down Arrows: Cycle through your previous commands. Great for when you make a typo.
  • Ctrl + C: The "Emergency Stop." If a program is stuck or a server is running and you want to stop it, use this.

5. Terminal vs. Shellโ€‹

You will often hear these words used interchangeably, but there is a slight difference:

  • Terminal: The window/app you open (e.g., Command Prompt, Terminal.app, iTerm2).
  • Shell: The "engine" running inside the window that processes your commands (e.g., Bash on Linux, Zsh on Mac, or PowerShell on Windows).

Practice: The "Speed Builder" Challengeโ€‹

Try to perform this entire workflow without touching your mouse:

  1. Open your terminal.
  2. Navigate to your Desktop: cd Desktop.
  3. Create a new folder: mkdir code-hub-practice.
  4. Enter that folder: cd code-hub-practice.
  5. Create three files at once: touch index.html style.css script.js.
  6. List the files to confirm they exist: ls.
  7. Open the whole folder in VS Code: code . (Note: This requires the 'code' command to be installed).
A Note on 'rm'

Unlike deleting a file with your mouse, using rm in the terminal does not send the file to the Recycle Bin/Trash. It is gone forever. Always double-check before hitting Enter!

Customizing

Once you get comfortable, you can customize your terminal with themes and plugins (like Oh My Zsh) to make it look beautiful and show you which Git branch you are currently on!