Command Reference
Note Don’t type the
[]
brackets when using the command -cd [dirname]
means you’ll typecd 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
Navigating your directories/folders
If you installed Cmder, you can use the OS X command for almost everything
OS X command | description | Windows version |
---|---|---|
pwd |
Prints working directory — use this to check that you’re in the directory you want | chdir |
cd [dirname] |
Changes directory, moves you into the folder named dirname |
same |
cd .. |
Moves you up one directory, e.g. from Desktop/foundations/class-1 to Desktop/foundations . |
same |
ls : lists subdirectories (and files). ls -lah is nicer, though. |
dir |
|
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 | dir (see here |
Moving/editing/downloading files
If you installed Cmder, you can use the OS X command for almost everything
OS X command | description | Windows version |
---|---|---|
mv [source] [destination] |
Moves a file from one place to another | move |
cp [source] [destination] |
Copies a file from one place to another (so now you have two) | copy |
rm [file] |
Deletes (removes) a file | del |
mkdir [directoryname] |
Creates a directory | same |
rmdir [directoryname] |
Deletes (removes) a directory | same |
tar cvf [filename] [filename] [filename]... |
Compresses (zips) files up into a .tar.gz file |
Use zip files + 7za |
tar xvf [filename] |
Extracts (unzips) a .tar.gz file |
Use zip files + 7za |
curl [url] |
Downloads a file, but streams it into your terminal window | same (need to install cURL) |
curl -O [url] |
Downloads a file, saving it | |
wget [url] |
Downloads a file, saving it (yes, curl and wget are pretty similar) same (need to instal wget) |
Looking at individual files
OS X command | description | Windows version |
---|---|---|
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) | |
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) | same |
grep [text] [filename] |
Show all of the lines in filename that contain text (OS X) |
findstr or find |
sort |
Sorts the lines of a file | same |
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.