Skip to content

Command Line Crash Course

The command line is just a way to manually enter text commands in an application called a terminal. Instead of clicking on icons or using a graphical interface, you type commands into the terminal and receive text responses. This can be a powerful way to perform tasks, especially for tasks that don't have a graphical interface.

  • To execute a command, type it in the terminal application and press Enter or Return.
  • The Tab key can be used for auto-completing file names or commands.
  • Command (⌘) (or Ctrl) + C can be used to stop a running command.
  • The up and down arrow keys allow you to cycle through your previously used commands.

IMPORTANT: The commands below are specific to MacOS and other Unix-based systems. Commands on Windows differ slightly than Unix-based systems; for a quick Windows-specific command line tutorial, see this one.

The most common commands you'll use are:

  1. cat: Displays the content of a file or concatenates multiple files.

    • Example: cat file.txt
  2. cd: Changes the current directory.

    • Example: cd Documents to go to the Documents directory.
  3. cp: Copies files or directories.

    • Example: cp source.txt destination.txt to copy source.txt to destination.txt.
  4. ls: Lists all files and directories in the current directory.

    • Example: ls
  5. man: Displays the manual page for other commands.

    • Example: man ls to see the manual for the ls command.
  6. mkdir: Creates a new directory.

    • Example: mkdir NewFolder to create a new folder named "NewFolder".
  7. mv: Moves or renames files or directories.

    • Example: mv oldname.txt newname.txt to rename a file.
  8. pwd: Displays the path of the current working directory.

    • Example: pwd
  9. rm: Removes files or directories.

    • Example: rm file.txt to remove a file named "file.txt".
  10. touch: Creates a new, empty file.

    • Example: touch newfile.txt