Note Don’t type the [] brackets when using the command - cd [dirname] means you’ll type cd Documents.

Being lazy

  • Press ↑ and ↓ to scroll through previous commands. It can save you a lot of typing.
  • Instead of typing out a long file/directory name, type the first few letters and then press tab. It will automatically fill in the rest of the filename. Use this every time you’re typing anything on the command line.
  • On a mac, you can drag a file or folder from Finder onto the Terminal and it will automatically type the full path

Not all of these commands work in PowerShell! This is a kind of okay reference about equivalents that might maybe possibly be useful. It might be better to google, though.

  • pwd: prints working directory — use this to check that you’re in the directory you want
  • cd [dirname]: changes directory, moves you into the folder named dirname
  • cd ..: moves you up one directory, e.g. from Desktop/foundations/class-1 to Desktop/foundations.
  • ls: lists subdirectories (and files). ls -lah is nicer, though.
  • locate [filename]: tries to find a file called filename and tell you where it’s at. It uses a database that isn’t updated too often, so it can’t always find new files.
  • find: tries to find a file without waiting for the database to update - can search by name, size, date modified, etc. This is a good reference

Moving/editing/downloading files

  • mv [source] [destination] moves a file from one place to another
  • cp [source] [destination] copies a file from one place to another (so now you have two)
  • rm [file] deletes (removes) a file
  • mkdir [directoryname] creates a directory
  • rmdir [directoryname] deletes (removes) a directory
  • tar cvf [filename] [filename] [filename]... compresses (zips) files up into a .tar.gz file
  • tar xvf [filename] extracts (unzips) a .tar.gz file
  • curl [url] downloads a file, but streams it into your terminal window
  • curl -O [url] downloads a file, saving it
  • wget [url] downloads a file, saving it (yes, curl and wget are pretty similar)

Looking at individual files

  • cat [filename]: displays the contents of a file
  • wc [filename]: displays the word count of a file (OS X)
  • wc -l [filename]: displays the line count of a file (OS X)
  • measure -lines [filename]: displays the line count of a file (PowerShell)
  • head -n 10 [filename]: displays the first 10 lines of a file (OS X)
  • tail -n 20 [filename]: displays the last 20 lines of a file (OS X)
  • more [filename]: displays the contents of a file one screen at a time (spacebar to continue)
  • grep [text] [filename]: show all of the lines in filename that contain text (OS X)
  • sls [text] [filename]: show all of the lines in filename that contain text (PowerShell)
  • sort: sorts the lines of a file
  • uniq: removes duplicate adjacent lines of a file

Amusing ones to look up

  • banner
  • cowsay
  • say

Others you might find useful if you love the command line

  • sed
  • awk
  • vi/vim

Escaping commands

Has something gone wrong? Taking too long? Hold down Control and hit C, a.k.a. Ctrl+C. You can also try Esc, q, and typing exit.

Learning more/finding more

man pages are manuals that you can use from the command line. They’re usually terrible and it’s easier to just google for examples.

man grep would give you the entry for grep, and then you’d use the d and u to navigate up and down. You should probably just google grep man page or grep examples, though.