Contents
Overview
It’s very useful to know how to use a command-line interface (CLI) inside a shell. At the NDCLab, you will need this knowledge to work with GitHub and the FIU HPC, among other applications.
Opening a Shell
Mac
On OS releases starting from Catalina, the default shell provided is Zsh which is very similar to Bash because both are POSIX compliant. This is good because shell scripts written in either scripting language will be usable on either macOS or Windows without tweaks.
To access Zsh, open up a normal terminal simply by clicking on the Terminal application on your Mac.
Windows
Install Git first. Check out these instructions.
Navigate to any location on your machine (although one suggests selecting a location where you will do all your NDCLab work), right-click, and select “Git Bash Here” from the menu. This opens a Bash shell where you can input shell and git commands.
(There is a different option that uses the Command Prompt. Using the Command Prompt is not recommended since it uses a different tool set which is not covered in this guide.)
Linux
There are many ways to open a shell on Linux. One example: right-click your desktop and select “Open Terminal” from the menu.
Shell Tips
Key Terms
Here is some of the key terminology used in working with a shell:
- command: an instruction from you (the user) to your computer.
- directory: another name for a folder. When you navigate around your files using the shell, you’re always “sitting” in a directory (called your “current directory”).
- option: an option that the program will allow you to change using special formatting, generally denoted with a “–” in front of the option name. For example “–option value”.
- flag: an option that can be on or off, generally denoted with a “-“ in front of the name. For example “-t”.
Important Commands
ls
ls
will list the files and directories that live within the directory that you are currently “in.” This is useful to see what is in your current directory, but it can also show you the contents of any directory as long as you provide a valid path to that directory and you have permission to view that directory.
Example:
# ls without options (outputs results on one line)
ls
#> Downloads Desktop stories.txt ...
# ls with the flag option -l (outputs one result per line)
ls -l
#> drwxr-xr-x - username 31 May 10:35 Desktop
#> drwxr-xr-x - username 9 Oct 14:52 Downloads
#> drwxr-xr-x - username 25 Aug 17:00 stories.txt
cd
cd
(change directory) is a shell command that allows you to move from one directory to another. This is useful to move around in the shell and, like ls
, it will accept any valid path to any directory.
There are two kinds of paths:
Relative paths, which are path names relative to your current directory. This path can start with either .
for the “current directory or ..
for “the directory above this directory”.
Absolute paths are paths that start from the root of the file-system (/
in macOS or c:/
in Windows).
Example:
# Example with a relative path
# Current directory: /home/user/proj_dir/
cd ./sub_folder/
# Current directory: /home/user/proj_dir/sub_folder/
# Example with an absolute path
# Current directory: /c/Users/username/Desktop/
cd /c/Users/
# Current directory: /c/Users
# Shortcut to go up one level
# Current directory: /home/user/proj_dir/sub_folder/
cd ..
# Current directory: /home/user/proj_dir/
# Shortcut to return home
# Current directory: /home/user/proj_dir/sub_folder/
cd ~
# Current directory: /home/
mkdir
mkdir
(make directory) is a shell command that allows you to create a new directory. This is useful to create a folder on your local where you can store files. You can name your directory anything that relates to the content within the directory.
Example:
# This example will create a directory named github on your local machine:
mkdir github
# Make sure you are in the desired location when you create a new directory.
# To check where you are currently at (seeing the contents of your current directory), use:
ls
# To navigate to your root (on Mac), use:
cd ~
Additional Resources
Here are several Linux cheat sheets with useful commands. Not all of these commands will work on Windows and macOS, but most of the core commands are the same with Linux and will therefore work.