Command Line#
The Unix shell#
The Unix shell is both a command-line interface (CLI) and a scripting language, allowing such repetitive tasks to be done automatically and fast.
The most popular Unix shell is Bash. Bash is the default shell on most modern implementations of Unix and in most packages that provide Unix-like tools for Windows. Note that ‘Git Bash’ is a piece of software that enables Windows users to use a Bash like interface when interacting with Git.
Bash#
“Bash is a popular default shell on Linux and macOS. Git Bash is a package that installs Bash, some common bash utilities, and Git on a Windows operating system.”
If you are running Linux and macOS, Bash should be available. If you are running Windows, you need to install GitBash.
Based on Software Carpentry lesson
Review of Command Line#
We will begin with an overview of the Command line (also command shell).
For additional practice, you can look at this The Unix Shell workshop
Review of the Command Line#
During this workshop, you’ll be communicating with GitHub from your local computer via the command line (the Terminal or the Git Bash on Windows). This section reviews some of the basic commands that will also be used in this workshop.
In addition to the command line, you’ll be using your text editor and your browser. Before continuing, its important that we clearly distinguish between these three different spaces or environments:
Your plain text editor where you’ll be writing your document is on your local computer.
That document is initially saved in a git-enabled repository on your local computer.
Your browser is where you’ll be uploading your repository to GitHub, a cloud service.
Your terminal is where you’ll be communicating with GitHub to send the repository and project files back and forth between the cloud (which you can view through the GitHub website) and your hard drive.
Because you’ll be moving between these three spaces throughout the workshop, you may want to use (command (⌘) + tab) or (control + tab) to move quickly between the three windows on your desktop.
Accessing the Terminal#
macOS#
Hold the command (⌘) key and press the space bar at the same time to bring up the “Spotlight Search” window. Type terminal
, followed by enter to quickly open the Terminal.
Windows#
Press the windows button on your keyboard. When the search menu pops up, type git bash
and press enter.
Making a Projects Folder#
In this session, we will be making a syllabus and using Git to keep track of our revisions. Let’s create a Git project folder.
If you don’t have a projects folder on your desktop, create one using the following command:
$ mkdir projects
From Desktop
, Navigate into your projects
folder using the following command:
$ cd projects
Then create a git-practice
folder with the following command:
$ mkdir git-practice
Navigate into the new git-practice
folder using the following command:
$ cd git-practice
At this point, when you type pwd
, your folder structure should look like this:
$ pwd
/home/<username>/Desktop/projects/git-practice
TO see what files are in a folder, ls
, it will show what files are there. To see all files, including invisible, type ls -a
$ ls
$ ls -a
Authenticating to Remote Git Repositories
“Git provides multiple protocols for authenticating to and interacting with remote Git repositories.
There are three main approaches you can take:
Using a personal authentication token or password
Using an SSH key
Using your GitHub password with 2-factor authentication”
See these directions from Berkeley Statistics
For additional directions, see Github’s Authentication documentation
Evaluation#
Which command do you use to make a new folder?
pwd
cd
mkdir
*
Which command do you use to enter into a folder?
pwd
cd
*mkdir
Which command do you use to check where you are?
pwd
*cd
mkdir
Pro-tip for the Command Line: How to exit unknown screens#
If you’re ever stuck or “trapped” on the command line, try running through these common exit commands to return to the prompt:
control + c
control + d
q
followed by enter:q
followed by enter
control + c attempts to abort the current task and restore user control. control + d escapes the current shell environment—if you use it at the normal $
prompt, it will end the current command line session. q
is often used as a command (followed by enter) to escape from specific programs like less
. :q
is the command used in vi
that changes the mode of interaction (:
), allowing you to enter the q
, a one-letter command to quit, which must be followed by enter. Thus, it’s a command specific to vi
.
Evaluation#
Which best describes where you are working when you’re writing in your plain text editor:
on my local machine*
on the internet
Which best describes where you are working when you’re using your terminal to communicate with GitHub and share the files:
on my local machine*
on the internet
Which best describes where your files are when you are viewing them in GitHub:
on my local machine
on the internet*
Git-enabled repository means
none of the files on my local machine are being tracked
a specific file on my local machine is being tracked
a specific folder on my local machine is being tracked*
all the files on my local machine are being tracked
Which command do you use to make a new folder?
pwd
cd
mkdir
*
Which command do you use to enter into a folder?
pwd
cd
*mkdir
Which command do you use to check where you are?
pwd
*cd
mkdir
Shell Cheat Sheets#
Action |
Files |
Folders |
---|---|---|
Inspect |
ls |
ls |
View content |
cat |
ls |
Navigate to |
cd |
|
Move |
mv |
mv |
Copy |
cp |
cp -r |
Create |
nano |
mkdir |
Delete |
rm |
rmdir, rm -r |