Once you've logged on, you're now at a Linux command line in your Home directory!
It looks as if you're running directly on the remote computer, but really there are two programs communicating:
There are many shell programs available in Linux, but the default is bash (Bourne-again shell).
Your Terminal is pretty "dumb" – just sending what you type over its secure sockets layer (SSL) connection to the remote computer, then displaying the text sent back by the remote computer's shell. The real work is being done on the remote computer, by executable programs called by the bash shell (also called commands, since you call them on the command line).
![]()
When you type something in at a bash command-line prompt, it Reads the input, Evaluates it, then Prints the results, then does this over and over in a Loop. This behavior is called a REPL – a Read, Eval, Print Loop.
Many programming language environments have REPLs – Python and R for example. The usual input to the bash REPL is a command, possibly with options and arguments.
Here are some examples of the ls command (list information about files) and some of its usage. Options to ls control how the information is listed, and arguments specify what is listed.
ls # example 1 - no options or arguments
ls -l # example 2 - one "short" (single character) option (-l)
ls --help # example 3 - one "long" (word) option (--help)
ls haiku.txt # example 4 - one argument, a file name (haiku.txt)
ls --width=20 # example 5 - a long option with a value
# (--width is the option, 20 is the value)
ls -w 20 # example 6 - a short option w/a value, as above,
# where -w is the same as --width
ls -l -a -h # example 7 - three short options entered separately
# (-l -a -h)
ls -lah # example 8 - three short options that can be
# combined after a dash (-lah) |
A command consists of:
The shell executes the command line input when it sees a linefeed, which happens when you press Enter after entering the command.
The notes below apply to nearly all built-in Linux utilities, and to many 3rd party programs as well
Some handy options for ls:
The arguments to ls are one or more file/directory names. If no arguments are provided, the contents of the current directory are listed. If an argument is a directory name, the contents of that directory are listed.
What is the difference between typing just ls (then Enter), and ls -a (then Enter)?
ls by itself displays names of the files and sub-directories in your current Home directory, other than dot files.
ls -a shows all files, including dot files whose names start with a period ( . ) which are normally not listed
|
What do you see when you enter ls -l?
A long listing files and sub-directories in your current Home directory, other than dot files.
|
How can you tell which entries are files and which are directories?
Because of the coloring ls applies to its output, directories are a different color (e.g. yellow or blue) than files (white). Also, in a long listing, the left-most permissions display will start with a "d" for directories (e.g. |
What is the file size of the file mobydick.txt in bytes? In Kilobytes (1,024s of bytes, denoted K)
ls -l |
ls -l shows mobydick.txt file size of 12319 bytes |
So how do you find out what options and arguments a command uses?
Every Linux command has tons of options – most of which you'll never use! The trick is to start with the most commonly used options and build out from there. Then, if you need a command to do something special, check if there's an option already to do that.
A good place to start learning built-in Linux commands and their options is on our Some Linux commands page.
How would you produce a long listing that is sorted by last modification time?
ls --help | more |
The -t option produces output sorted by modification time, most recent files first. ls -l -t |
How would you change the sort order to show the oldest files first?
The -r option reverses the sort order. ls -l -t -r |
Some 3rd party tools, especially bioinformatics tools, may bundle a number of different functions into one command. For these tools, just typing in the command name then Enter will provide top-level usage information. For example, the bwa tool that aligns sequencing reads to a reference genome:
bwa |
Produces something like this:
Program: bwa (alignment via Burrows-Wheeler transformation)
Version: 0.7.16a-r1181
Contact: Heng Li <lh3@sanger.ac.uk>
Usage: bwa <command> [options]
Command: index index sequences in the FASTA format
mem BWA-MEM algorithm
fastmap identify super-maximal exact matches
pemerge merge overlapping paired ends (EXPERIMENTAL)
aln gapped/ungapped alignment
samse generate alignment (single ended)
sampe generate alignment (paired ended)
bwasw BWA-SW for long queries
shm manage indices in shared memory
fa2pac convert FASTA to PAC format
pac2bwt generate BWT from PAC
pac2bwtgen alternative algorithm for generating BWT
bwtupdate update .bwt to the new format
bwt2sa generate SA from BWT and Occ
Note: To use BWA, you need to first index the genome with `bwa index'.
There are three alignment algorithms in BWA: `mem', `bwasw', and
`aln/samse/sampe'. If you are not sure which to use, try `bwa mem'
first. Please `man ./bwa.1' for the manual. |
bwa, like many bioinformatics programs, is written as a set of sub-commands. This top-level help displays the sub-commands available. You then type bwa <command> to see help for the sub-command:
bwa index |
Displays something like this:
Usage: bwa index [options] <in.fasta>
Options: -a STR BWT construction algorithm: bwtsw or is [auto]
-p STR prefix of the index [same as fasta name]
-b INT block size for the bwtsw algorithm (effective with -a bwtsw) [10000000]
-6 index files named as <in.fasta>.64.* instead of <in.fasta>.*
Warning: `-a bwtsw' does not work for short genomes, while `-a is' and |
Of course Google also works on 3rd party tools (e.g. search for bwa manual). And these days ChatGPT and similar chatbots are also quite useful.
Sometimes you want to repeat a command you've entered before (since you last logged in), possibly with some changes.
The command line cursor (small thick bar on the command line) marks where you are on the command line.
Once the cursor is positioned where you want it:
Hitting Tab when entering command line text invokes shell completion, instructing the shell to try to guess what you're doing and finish the typing for you. It's almost magic!
On most modern Linux shells you use Tab completion by pressing:
Let's have some fun with our friend the Tab key. Follow along if you can, as we use the Tab key to see the /stor/work/CBRS_unix/fastq path.
ls /st # press Tab key - expands to /stor/ which
# is the only match
ls /stor/w # press Tab key again: expands to /stor/work/,
# again the only match
ls /stor/work/C # press Tab once - you hear a "bell" sound,
# and nothing is displayed because
# there are multiple matches
ls /stor/work/C # press Tab a 2nd time - all matching
# entries are listed
ls /stor/work/CB # press Tab key - expands to
# /stor/work/CBRS_unix
ls /stor/work/CBRS_unix/ # press Tab twice to see all completions
ls /stor/work/CBRS_unix/f # press Tab once - expands to
# /stor/work/CBRS_unix/fastq
|
Tab key completion also works on commands! Type "bowtie" and Tab twice to see all the programs in the bowtie2 and bowtie tool suites.
You know the command line is ready for input when you see the command line prompt. It can be configured differently on different systems, but on our system it shows your account name, server name, current directory, then a dollar sign ($). Note the tilde character ( ~ ) signifies your Home directory.
student01@gsafcomp01:~$ |
Like everything in Unix, the command line has similarities to a text file. And in Unix, all text file "lines" are terminated by a linefeed character (\n, also called a newline).
Note: The Unix linefeed (\n) line delimiter is different from Windows, where the default line ending is carriage-return + linefeed (\r\n), and some Mac text editors that just use a carriage return (\r). |
As mentioned above, the shell executes command line input when it sees a linefeed, which happens when you press Enter after entering the command.
But you can enter more than one command on a single line – just separate the commands with a semi-colon ( ; ).
ls haiku.txt; ls -lh |
You can also split a single command across multiple lines by adding a backslash ( \ ) at the end of the line you want to continue, before pressing Enter.
student01@gsafcomp01:~$ ls haiku.txt \ > mobydick.txt |
Notice that the shell indicates that it is not done with command-line input by displaying a greater than sign ( > ). You just enter more text then Enter when done.
At any time during command input you can press Ctrl-c (Control key and the c key at the same time) to get back to the command prompt. This is true whether you're entering a single command line prompt or at a > continuation. |
In the bash shell, and in most tools and programming environment, there are two kinds of input:
There are many metacharacters in bash: # \ $ | ~ " ' [ ] to name a few.
We'll be pointing out the different metacharacters and their usages – which can depend on the context where they're used – as we learn more about bash.
When using the backslash ( \ ) to continue a text line, be careful not to enter any text after the backslash – just press Enter after it. |
The backslash ( \ ) metacharacter is used to escape the next character, which means to treat it as a literal even if it is a metacharacter. Normally, pressing Enter acts as a line termination linefeed metacharacter. When you type the backslash ( \ ) metacharacter, then Enter , instead of treating Enter as a metacharacter – ending the line and starting a new one – the shell treats Enter as a literal and inserts a literal linefeed character ( \n ) in the text, which performs a linefeed operation and gives you the > prompt on a new line. |
You don't always type in commands, options and arguments correctly – you can misspell a command name, forget to type a space, specify an unsupported option or a non-existent file, or make all kinds of other mistakes.
What happens? The shell attempts to guess what kind of error it is and reports an appropriate error message as best it can.
Some examples:
# You mis-type a command name, or a command not installed on your system student01@gsafcomp01:~$ catt catt: command not found # You try to use an unsupported option student01@gsafcomp01:~$ ls -z ls: invalid option -- 'z' Try 'ls --help' for more information. # You specify the name of a file that does not exist student01@gsafcomp01:~$ ls xxx ls: cannot access 'xxx': No such file or directory # You try to access a file or directory you don't have permissions for student01@gsafcomp01:~$ cat /etc/sudoers cat: /etc/sudoers: Permission denied |