Terminology:
- Linux: an open-source operating system (OS)
- Unix: considered a category of OS now. Used to be an influential OS that influenced the design of many other operating systems
- terminal v. shell: terminal is the app that allows us to type to a command line. The shell is what interprets and runs the commands you write and interacts with the computer’s operating system (OS).
- bash: one of the most popular shells
- zsh: the default shell for Macs. Made to improve bash while maintaining backward compatability
Shortcuts:
- ctrl + c to kill the program that’s currently running
- up and down key (for history, accessing commands you used previously)
- tab for automatic completion, useful when your file or directory names are very long
Special Names
-
.
(dot) a special directory name that means the directory you are currently inside of with the shell -
..
(dot dot): a special directory name that refers to the directory that is the parent of (or above) the current directory. -
~
(home): a special directory that is assigned to each user. It contains user-specific configuration files (i.e. .bashrc or .vimrc)
Common Commands
-
mv
(move): can rename a file or move a file to a different directory.- to rename:
mv <source_file> <dest_directory/dest_file>
- to move:
mv <source_file> <dest_directory>
- to rename:
-
cp
(copy): can create a duplicate file in a directory of your choosing, or can overwrite a file with another file’s contents.- dupe file:
cp <source_file> <dest_directory>
- overwrite:
cp <source_file> <dest_file>
- dupe file:
-
ls
(list): displays files and directories in the directory you’re currently in. Files and directories that start with.
(known as hidden files or directories) are not included, unless you add the-a
flag:ls -a
. -
cd
(change directory): changes your current location to a different directory that you specify.cd <directory_name>
-
touch
: most often used to create new files. Can also be used to change the timestamps associated with the file. Both purposes can be achieved withtouch <filename>
-
rm
(Remove): used to remove (delete) a file. Usage:rm <file-to-delete>
-
man
(manual): displays the documentation of a command when you typeman <command>
. Documentation includes command name, description, return values (if applicable), and other info that may or may not be relevant in your current case. -
mkdir
(make directory): used to add new directories. Use -p flag and provide a path if you want all directories in the path to be created if they don’t yet exist.mkdir <directory_name>
mkdir -p <path/of/multiple/directories>
-
rmdir
(remove directory): will remove the directory specified if that directory is empty (no files or other directories inside). If not empty,rmdir
will fail.- if you wish to delete the non-empty directory and its contents, use
rm -r <directory_name>
- if you wish to delete the non-empty directory and its contents, use
-
vim
: Vim is a command line editor that Travis uses for most coding. You do not need to use it, but it is one of the most popular editors. There are more resources on Vim in the rescources & tools section of the website if you are intersted. Example Usage:vim <file-i-want-to-open>
-
history
: a command that prints out a history of recent commands used. Particularly useful in combination with grep. For example, if I forgot a command that I used recently that had “valgrind” in it, I could typehistory | grep valgrind
and it will show all commands I used recently that had the wordvalgrind
in it.
Note: the above descriptions for commands are brief and are meant to highlight the most common use cases. There are other flags or argument formatting that are not covered in this reference sheet, but I encourage you to look these commands up if you are curious.