The Unix Shell
The shell
(also known as the command-line
) is a program that allows us to tell the computer what to do by giving it a “command”.
Another common way we tell the computer what to do is through the use of a “point and click” graphical user interface (GUI) approach.
Isn’t pointing and clicking easier?
Imagine you had the following task:
You have a directory with 10 .txt
files.
Pull the first line from each file into a single new file. You should end up with a list of all of the first lines.
Take a look below to see the process for GUI and CLI.
Imagine you had the following task:
You have a directory with 10 .txt
files.
Pull the first line from each file into a single new file. You should end up with a list of all of the first lines.
Take a look below to see the process for GUI and CLI.
1. Create new file
2. Open file 1, copy line 1, paste into new file, close file 1.
3. Open file 2, copy line 1, paste into new file, close file 2.
4. Repeat 7 more times
head -n1 -q *.txt > new-file.txt
For this task, the GUI was tedious, time-consuming, and error-prone while the CLI was a single-command, quick, and relatively error proof.
Let’s start using the shell
.
Open the shell
(terminal
) on your computer.
Git
option.Git Bash
.Utilities
.Terminal
.Once we open our terminal, the $
shows us that shell
is ready for input.
Let’s see what day it is using the ls
command.
ls
stands for listIn your terminal, type ls
and press enter.
count.sh
example.gtf
exercise-data
fastqc.sh
fastqc_step.sh
feature_counts.sh
index
metadata.txt
north-pacific-gyre
rnaseq
rnaseq.sh
simulated_reads
star.sh
thesis
trim.sh
trim_fq.sh
Before we learn more commands, let’s learn about the structure of commands.
Commands follow a general syntax
command
option/flag
argument
command
– the main commandoption/flag
– modifies the behavior of the command, often optionalargument
– the source and/or target of the command, sometimes optionalLet’s change the way ls
command behaves by providing a value for the option
.
In your terminal, type ls -F
and press enter.
count.sh
example.gtf
exercise-data/
fastqc.sh
fastqc_step.sh
feature_counts.sh
index/
metadata.txt
north-pacific-gyre/
rnaseq/
rnaseq.sh
simulated_reads/
star.sh
thesis/
trim.sh
trim_fq.sh
This -F
option/flag returns the output in a different format, with a /
following directories and @
preceeding symbolic links.
To better understand command usage and their options we can use the following (depending on the command).
Method of getting help | Description | Example |
---|---|---|
--help or -h option/flag |
Displays help menu for the command/program | ls --help |
man command |
Displays the manual for the command/program in-depth | man ls |
The shell provides (usually) helpful and informative error messages.
For example, if you look closely at the ls --help
example above, you’ll see that the usage of --help
actually resulted in an error (see below).
Q&A: What is the error telling us?
Q&A: What is the error above telling us?