Skip to content

Useful commands

  • 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.
  • find: tries to find a file, can search by name, size, date modified, etc. This is a good reference. A terrible fun fact is that there are different versions of the find command, and they're sliiightly different.

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
  • wc -l [filename]: displays the line count of a file
  • head -n 10 [filename]: displays the first 10 lines of a file
  • tail -n 20 [filename]: displays the last 20 lines of a file
  • 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.
  • sort: sorts the lines of a file
  • uniq: removes duplicate adjacent lines of a file

Others you might find useful if you love the command line

  • sed
  • awk

Learning more/finding more

man pages are manuals that you can use from the command line.

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, man pages are awful.