Skip to content

Command Line (course memo)

The command line is a way to control your computer through a textual interface.

Terminology

Used interchangeably (small technical differences exist, not important for now): Command Line, Command Prompt, Terminal, Console, Shell, cmd — all refer to the window you type commands into.

File browser = Windows Explorer (Windows) / Finder (macOS) / Nautilus (Linux) — the GUI equivalent.

Terminal on different OSes

The commands below are Unix commands. macOS and Linux are both Unix-based, so they work natively there. Windows isn't Unix-based, so its standard Command Prompt doesn't understand them — this course uses git bash, a Unix-compatible layer on top of Windows that translates these commands. (Later, a full Linux environment via WSL2 is worth learning, but not needed yet.)

Basics

  • Running a command is like calling a function — sometimes it prints output, sometimes not (even on success).
  • You're always "in" one folder, the working directory (like having one folder open in a file browser).
  • pwd — print working directory (shows where you currently are).
  • cd <path> — change directory.
    • Absolute path: starts from the filesystem root, works regardless of current directory. E.g. cd /Users/username/Documents/Code.
    • Relative path: relative to the current working directory. E.g. from /Users/username/Documents/Code, cd example goes to /Users/username/Documents/Code/example.
    • . = current directory (cd . does nothing, but useful with other commands).
    • .. = parent directory (cd .. goes up one level).
    • ~ = home directory (e.g. /Users/<username>). Combinable: cd ~/Code, cd ~/...
  • Commands take arguments separated by spaces, like a function call. man <command> opens a command's manual (often easier to just search the web instead).

Common commands

  • ls — list contents of the current directory. ls -la (or -l -a) — list with more detail (long format, including hidden files).
  • mkdir <name> — create a folder. Chain commands with &&: mkdir example && cd example.
  • touch <name> — create an empty file.
  • mv <source> <target> — move (or rename) a file/folder.
  • cp <source> <target> — copy a file/folder.
  • rm <path> — delete a file immediately. rm -r <path> — delete a folder (recursively) immediately.
    • Warning: deletion via rm is immediate and permanent, no trash/recycle bin — double-check the path before running it.