Useful commands¶
Navigating your directories/folders¶
pwd
: prints working directory — use this to check that you’re in the directory you wantcd [dirname]
: changes directory, moves you into the folder named dirnamecd ..
: 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 thefind
command, and they're sliiightly different.
Moving/editing/downloading files¶
mv [source] [destination]
moves a file from one place to anothercp [source] [destination]
copies a file from one place to another (so now you have two)rm [file]
deletes (removes) a filemkdir [directoryname]
creates a directoryrmdir [directoryname]
deletes (removes) a directorytar cvf [filename] [filename] [filename]...
compresses (zips) files up into a .tar.gz filetar xvf [filename]
extracts (unzips) a .tar.gz filecurl [url]
downloads a file, but streams it into your terminal windowcurl -O [url]
downloads a file, saving itwget [url]
downloads a file, saving it (yes,curl
andwget
are pretty similar)
Looking at individual files¶
cat [filename]
: displays the contents of a filewc [filename]
: displays the word count of a filewc -l [filename]
: displays the line count of a filehead -n 10 [filename]
: displays the first 10 lines of a filetail -n 20 [filename]
: displays the last 20 lines of a filemore [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 fileuniq
: 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.