Basic Terminal Tutorial
In the examples below, content in small capital letters set in a monospace typeface, such as file
and folder
, indicate filler content, such as a file or folder from your computer. Content you’d type into The Terminal is also set in a monospace typeface, but surrounded by a light blue background.
- ./
- The current directory.
- ../
- The parent of the current directory.
- alias
- Displays all aliases (keyboard shortcuts), usually in a file called
.bash_aliases
, assigned to commands. Note: To run the default version of any command to which an alias has been assigned, precede it with a backslash (\
). For example, running \rm in my terminal would bypass my alias of'rm -i'
. - code
- Launches vs Code, assuming the shell commands have been installed. Typing code . opens the current folder in vs Code, and typing code file opens
file
in vs Code. - cat file
- Displays the contents of
file
, then returns control to The Terminal. - cd
- Changes directory to your home folder, which is likely
~/Users/your_name
. Typing cd folder changes intofolder
and typing cd ../folder changes into a directory calledfolder
in the current directory’s parent. Typing cd from anywhere in your directory tree will take you home. - 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 commands typed 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 any non-existing intermediate folders without having to create each of the intermediate folders individually. For example, assume foldersa
,
, andb
c
don’t exist. Running mkdir -p a/b/c would create folderc
inside folderb
inside foldera
. - 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. Type q to exit. - open .
- Opens the current folder (
.
) in macos’s Finder. Also does things like open aurl
in a browser. For example, open https://github.com/code-warrior launches the web address in your default browser. (In Cygwin,open
’s equivalent iscygstart
and in Ubuntu it’sxdg-open
.) - rm file
- Removes
file
. Some Linux and macos 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
- Shows the last 10 lines of
file
- touch file
- Creates a new, empty file called
file
. Iffile
exists,touch
does nothing. - type program
- Provides info about whether
program
is an alias, command, function, etc. Combine the-all
flag — for “all locations” — withtype
to see everything associated withprogram
. For example, type -all ls reveals on my system thatls
is aliased to`ls --color=auto'
and that it resides at/bin/ls
in my file system. - which program
- Locates and prints the path to
program
. For example, if you wanted to know where thels
program was installed, which ls would respond with/bin/ls
. Consider aliasingwhich
to type -all in order to get more info aboutprogram
.