Skip to main content
Back to module
Git & the Command Line · The Command Line

Opening a terminal

Reading38mLesson 1 of 3 in this module

Open a terminal on macOS, Linux or Windows and move around your folders with pwd, ls and cd.

Why it matters

Graphical apps are great for everyday work, but much technical work happens in a terminal: running code, using Git, connecting to servers, installing tools, automating repetitive tasks. Servers in the cloud usually have no desktop at all. Being comfortable at the command line is one of the clearest signs of a working developer, data scientist, or security or cloud engineer.

Terminal, shell, command

  • The terminal is the window you type into.
  • The shell is the program that reads your command and runs it. This course uses bash or zsh; the commands here work the same in both.
  • A command is a program name, often followed by options (flags such as -l) and arguments (such as a folder name): ls -l Documents.

Opening one

  • macOS: open Terminal (Spotlight: Cmd+Space, type "Terminal"). The default shell is zsh.
  • Linux: open Terminal from your apps menu (often Ctrl+Alt+T). The default shell is usually bash.
  • Windows: install Git for Windows from git-scm.com, which includes Git Bash, a bash terminal. Or install WSL (Windows Subsystem for Linux: run wsl --install in an administrator PowerShell, then restart) to get a full Ubuntu terminal. Both work for this course. The built-in Command Prompt and PowerShell use different commands, so use Git Bash or WSL here.

You will see a prompt, something like alex@laptop ~ % or alex@laptop:~$. It is waiting for a command. Type one and press Enter.

Where am I? pwd

The terminal is always "in" one folder (directory), the working directory. pwd (print working directory) shows it:

$ pwd
/Users/alex

On Linux and WSL it looks like /home/alex; in Git Bash, /c/Users/alex. The $ here just stands for your prompt; do not type it.

What is here? ls

$ ls
Desktop  Documents  Downloads  Pictures
$ ls -l          # long format: permissions, size, date
$ ls -a          # include hidden files (names starting with .)
$ ls -la Documents

Text after # is a comment and is ignored by the shell.

Moving: cd

$ cd Documents        # go into Documents (relative path)
$ cd ..               # up one level
$ cd ~                # home folder (plain cd does the same)
$ cd /tmp             # absolute path, starts at the root /
$ cd -                # back to the previous folder
  • An absolute path starts with / (or ~, which means your home folder) and works from anywhere.
  • A relative path starts from where you are now. . means "this folder" and .. means "the parent folder".
  • Folder names with spaces need quotes: cd "My Projects".

In WSL, your Windows files are under /mnt/c/Users/<name>. In Git Bash they are under /c/Users/<name>.

Worked example

$ pwd
/Users/alex
$ ls
Desktop  Documents  Downloads
$ cd Documents
$ pwd
/Users/alex/Documents
$ cd ..
$ pwd
/Users/alex

Time-savers

  • Tab completion: type cd Doc and press Tab; the shell fills in Documents/. Press Tab twice to see options. This saves time and prevents typos.
  • History: the Up arrow brings back earlier commands.
  • Cancel: Ctrl+C stops a running command or clears the line.
  • Clear the screen: clear or Ctrl+L.
  • Help: man ls shows the manual (press q to quit). In Git Bash, use ls --help.

Common mistakes

  • Typing the $ from examples.
  • Wrong capitals: documents is not Documents on Linux (macOS usually ignores case, but do not rely on it).
  • Spaces in names without quotes: cd My Projects tries to go into My.
  • Not knowing where you are. When in doubt, run pwd.

Quick recap

  • The terminal runs a shell (bash or zsh); use Git Bash or WSL on Windows.
  • pwd shows where you are, ls lists what is there, cd moves.
  • Absolute paths start at / or ~; relative paths start where you are.
  • Tab completion, Up arrow and Ctrl+C make the terminal fast and safe.

Try it

Open the Do tab to set up your terminal and practice folder.

Also in this lesson: