1 Introducing the shell
1.1 What is the shell?
A shell is a program that lets you interact with your computer by typing commands. Instead of clicking on icons and menus, a graphical user interface (GUI),you type instructions and the computer responds with text output.
The shell we will use is called bash (Bourne Again SHell). It is the default on most Linux systems and on older Macs. On newer Macs the default is zsh, which is nearly identical for our purposes.
Why bother?
You might wonder why anyone would use a text interface when GUIs exist. Here are three reasons that matter in bioinformatics:
- Most bioinformatics tools have no GUI. Programs like BLAST, HMMER, Bowtie, and Samtools are run exclusively from the command line.
- Automation. When you need to process hundreds of files, a few lines of shell code replaces hours of pointing and clicking.
- Remote computing. High-performance computing clusters, where large genomic analyses actually run,are only accessible via the shell.
1.2 Opening the terminal
Depending on your operating system, you opened the terminal following the setup instructions in the Preface. You should see a window with some text and a blinking cursor. That text is the prompt.
1.3 The prompt (Am I ready?)
The prompt tells you the shell is waiting for input. It typically looks something like this:
username@computer:~$
The exact appearance varies, but what matters is the $ (or % on zsh) at the end this signals that the shell is ready. Do not type the $ when following examples in this workshop. It is shown only to indicate a command you should type.
1.4 Your first commands
Let’s run a few simple commands to get comfortable.
Identifying yourself (Who am I?)
The command whoami prints your username:
whoamiChecking the time (What time is it?)
The command date prints the current date and time:
dateClearing the screen (Clean slate)
The command clear clears the terminal screen. Your previous output is not lost you can still scroll up to see it.
clearThe keyboard shortcut Ctrl + L does the same thing as clear.
Printing text (Talking to yourself)
The command echo prints whatever you give it back to the screen:
echo "Hello, world"You will see echo again when we write scripts.
1.5 The anatomy of a command
Most shell commands follow this pattern:
command [options] [arguments]
- command: the programme to run (e.g.
ls) - options (or flags): modify the behaviour, usually starting with
-(e.g.-l) - arguments: the target the command acts on (e.g. a filename or directory)
We will see this pattern in action throughout the workshop.