Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

  • Macs and Linux have a Terminal program built-in – find it now on your computer
  • Windows 10 or later has ssh and scp in Command Prompt or PowerShell (may require latest Windows updates)
    • Open the Start menu → Search for Command
Expand
titleOther Windows ssh/Terminal options

If your Windows version does not have ssh in Command Prompt or PowerShell:

More advanced options for those who want a full Linux environment on their Windows system:

From now on, when we refer to "Terminal", it is either the Mac/Linux Terminal program, Windows Command Prompt or PowerShell, or the PuTTY program.

...

You're now at a command line! It looks as if you're running directly on the remote computer, but really there are two programs communicating:

  1. your local Terminal
  2. the remote Shell shell

There are many shell programs available in Linux, but the default is bash (Bourne-again shell).

The Terminal is pretty "dumb" – just sending what you type over its secure sockets layer (SSL) connection to TACC, then displaying the text sent back by the shell. The real work is being done on the remote computer, by executable programs (commands) called by the bash shell (also called commands, since you call them on the command line).

image-2023-4-26_9-27-6.png

...

The bash REPL and commands

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 input to the bash REPL is a command. Here are some examples:

Code Block
languagebash
ls               # example 1 - no options or arguments
ls -l            # example 2 - one "short" (single character) option only (-l)
ls --help        # example 3 - one "long" (word) option (--help)
ls .profile      # example 4 - one argument, a file name (.profile)
ls --width=20    # example 5 - a long option that has 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 command name – here ls (list files)
    • A command can be any of the built-in Linux/Unix commands, or the name of a user-written script or program
  • One or more options, usually noted with a leading dash (-) or double-dash (--).
    • -l in example 2 (long listing)
    • --help in example 3
    • Options are optional – they do not have to be supplied (e.g. example 1 above)
  • One or more command-line arguments, which are often (but not always) file names
    • e.g. .profile in example 4

The shell executes the command line input when it sees a linefeed, which happens when you press Enter after entering the command.

Command options

The notes below apply to nearly all built-in Linux utilities, and to many 3rd party programs as well

  • Short (1-character) options can be provided separately, prefixed by a single dash(-)
    • or can be combined with the combination prefixed by a single dash (examples 7, 8)
  • Long (multi-character/"word") options are prefixed with a double dash (--) and must be supplied separately.
  • Many utilities have equivalent long and short options (e.g.  --width and -w above)
  • Both long and short options can be assigned a value (examples 5, 6)
    • The short option and its value are usually separated by a space, but can also be run together (e.g. -w20)
    • Strictly speaking, the long option and its value should be separated by an equal sign (=) according to the POSIX standard (see https://en.wikipedia.org/wiki/POSIX). But many programs let you use a space as separator also.

Some handy options for ls:

  •  -l shows a long listing, including file permissions, ownership, size and last modified date.
  • -a shows all files, including dot files whose names start with a period ( . ) which are normally not listed
  • -h says to show file sizes in human readable form (e.g. 12M instead of 12201749)

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.

Getting help

So how do you find out what options and arguments a command uses?

  1. In the Terminal, type in the command name then the --help long option (e.g. ls --help)
    • Works for most Linux commands; 3rd party tools may use -h or -? or even /? instead
    • May produce a lot of output, so you may need to scroll up quite a bit or pipe the output to a pager (e.g. ls --help | more)
  2. Use the built-in manual system (e.g. type man ls)
    • This system uses the less pager that we'll go over later.
    • For now, just know that a space advances the output by one screen/"page", and typing q will exit the display.
  3. Ask the Google, e.g. search for ls man page
    • Can be easier to read

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 Linux fundamentals page.

Setting up your environment

...

Tip

You can copy and paste these lines from the code block below into your Terminal window. Just make sure you hit Enter after the last line.

...

Code Block
languagebash
titleCreate symbolic directory links
cd  # makes your Home directory the "current directory"
ln -s -f $SCRATCH scratch
ln -s -f $WORK work
ln -ssf -f /work/projects/BioITeam/projects/courses/Core_NGS_Tools CoreNGS

ls # you'll see the 3 symbolic links you just created

...

Tip

$WORK and $SCRATCH are TACC environment variables that refer to your Work and Scratch file system areas (more on these file system areas soon).

Environment variables are like variables in other programming languages: they have a name (WORK, SCRATCH) and hold a value ($WORK, $SCRATCH)

To see the value of an environment variable, use the echo command, then the variable name after a dollar sign ( $ ):

Code Block
languagebash
echo $SCRATCH


...

Expand
titleWhat is "ln -s" doing?

The ln -s command creates a symbolic link, a shortcut to the linked file or directory.

  • Here the link targets are your Work and Scratch file system areas
  • Having these link shortcuts will help when you want to copy files to your Work or Scratch, and when you navigate the TACC file system using a remote SFTP client
  • Always change directory (cd) to the directory where we want the links created before executing ln -s
    • Here we want the links under your home directory (cd with no arguments)

Want to know where a link points to? Use ls with the -l (long listing) option.

Code Block
languagebash
titlels -l shows where links go
ls -l


Anchor
Local_Bin_Setup
Local_Bin_Setup
Set up a $HOME~/local/bin directory and link several scripts a script there that we will use in the class.

...