Basic Terminal Tutorial
In the examples below, items in CAPS
are filler content representing an actual file or folder on your computer. Items you type into The Terminal appear in light blue.
- ./
- The current directory.
- ../
- The parent of the current directory.
- alias
- Displays all keyboard aliases (shortcuts), usually in a file called
.bash_aliases
. - atom
- Launches Atom, assuming the shell commands have been installed. Typing atom . opens the current folder in Atom and typing atom FILE opens
FILE
in Atom. - cat FILE
- Displays the contents of
FILE
, then returns control to The Terminal. - cd
- Changes directory to your home folder,
~/Users/YOUR_NAME
. Typing cd FOLDER changes intoFOLDER
and typing cd ../FOLDER changes into a directory calledFOLDER
in the current directory’s parent. - clear
- Clears the screen of any content, placing the cursor at the top of The Terminal’s window.
- cp FILE.txt COPY-OF-FILE.txt
- Copies the file
FILE.txt
to a new file calledCOPY-OF-FILE.txt
- head FILE.html
- Shows the first 10 lines of
FILE.html
- history
- Displays a history of all the typed commands into The Terminal.
- ls
- Displays the files and folders in the current directory, excluding those that start with a dot. Typing ls -a lists all files and folders that start with and without a dot. And, typing ls -d .* lists only files and folders that start with a dot.
- man COMMAND
- Displays the manual for
COMMAND
. - mkdir NEW_FOLDER
- Creates a new folder called
NEW_FOLDER
in the current directory. Using the-p
flag creates intermediate folders. For example, to create folderC
inside folderB
inside folderA
, none of which exists, you’d run mkdir -p A/B/C. - mv FILE FOLDER/
- Moves
FILE
insideFOLDER
.mv
is also used to rename a file. For example, mv FILE FILE_WITH_NEW_NAME renamesFILE
→FILE_WITH_NEW_NAME
- more FILE
- Render the contents of
FILE
one screenful at a time. You will need to type q to exit. - open .
- Opens the current folder in Mac OS X’s Finder. (This is a Mac-only command.)
- rm FILE
- Removes
FILE
. Some Linux and Mac OS systems don’t have a guard on therm
command, meaning that the user isn’t asked to verify the removal of a file. Because files removed withrm
aren’t retrievable, use the-i
flag so you can verify that, indeed, you want to remove a file. For example, rm -i FILE would ask if you want toremove FILE?
.
To recursively remove a folder, run rm -r FOLDER; and, to forcefully and recursively remove a directory without interaction, run rm -fr FOLDER. - sudo COMMAND
- Run
COMMAND
as the current user with privileged access. - tail FILE.html
- Shows the last 10 lines of
FILE.html
- touch FILE
- Creates a new, empty file called
FILE
. IfFILE
exists,touch
does nothing.