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
filein 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 intofolderand typing cd ../folder changes into a directory calledfolderin 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.txtto 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_folderin the current directory. Using the-pflag creates any non-existing intermediate folders without having to create each of the intermediate folders individually. For example, assume foldersa,, andbcdon’t exist. Running mkdir -p a/b/c would create foldercinside folderbinside foldera. - mv file folder/
- Moves
fileinsidefolder.mvis 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
fileone screenful at a time. Type q to exit. - open .
- Opens the current folder (
.) in macos’s Finder. Also does things like open aurlin a browser. For example, open https://github.com/code-warrior launches the web address in your default browser. (In Cygwin,open’s equivalent iscygstartand in Ubuntu it’sxdg-open.) - rm file
- Removes
file. Some Linux and macos systems don’t have a guard on thermcommand, meaning that the user isn’t asked to verify the removal of a file. Because files removed withrmaren’t retrievable, use the-iflag 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
commandas the current user with privileged access. - tail file
- Shows the last 10 lines of
file - touch file
- Creates a new, empty file called
file. Iffileexists,touchdoes nothing. - type program
- Provides info about whether
programis an alias, command, function, etc. Combine the-allflag — for “all locations” — withtypeto see everything associated withprogram. For example, type -all ls reveals on my system thatlsis aliased to`ls --color=auto'and that it resides at/bin/lsin my file system. - which program
- Locates and prints the path to
program. For example, if you wanted to know where thelsprogram was installed, which ls would respond with/bin/ls. Consider aliasingwhichto type -all in order to get more info aboutprogram.