1 Linux Basics

1.1 What are Linux, bash, and the NCGR Server?

A little shell… aka the $ prompt is the command line interface

  • A shell is a user interface to the operating system.
    • CLI (Command Line Interface)
    • GUI (Graphical User Interface)
  • Bourne-Again SHell (bash) is a Unix shell and command language
  • Each command drives a program or script by talking to the Operating System (Linux)

Directory Structure

In a Finder window, you would see this:

1.1.1 Find the terminal application you’ll use to log into the NCGR server

  • For Windows: search for “Tabby” from the Start menu

  • For Mac: search for “Tabby” using Spotlight (the magnifying glass in the top right of your Mac screen)

1.2 Connecting to the linux server

  1. Open your terminal.

  2. Type the following on your command line, substituting in your username for . Your username is usually the first letter of your first name and your last name (all lowercase).

ssh -p2309 <username>@inbre.ncgr.org

Notes:

  • Because we’re logging in remotely, the -p option is required to specify port 2309.
  • If you’re prompted to confirm the connection, say “yes”, then enter your password.
  • Your password will not show up when you type it but it is registering what you are typing.
  1. Enter your password.

  2. Change your password.

passwd

Enter you current password then the new password when prompted.

1.2.1 Now that I logged on, where am I?

You’re at the command line interface of NCGR’s analysis server!

To the left of the command prompt, you should see something like this:

Command output is shown after the “##” in this document.

1.3 Understanding Directories

print working directory (pwd), mkdir (make directory), and list contents (ls)

pwd
  • This is your “home” directory.

Now, create a dir under your home directory for this linux class:

mkdir linuxc

ls

1.4 Listing options

using the ls command

  • long list:
ls -l
  • long list, by time, reverse order -old to new:
ls -ltr

1.6 History command

lists the commands you have entered

history

Scroll through recent commands with the up and down arrows.

To perform a command from the list by number:

!17

To perform the last command you made:

!!

1.7 Files: creating by redirecting standard out

redirect operator >

To send output to a file instead of standard out:

  • standard out is just the terminal screen
history > history.txt

The cat command will print the contents of the file to the screen.

cat history.txt

Now you have a file with your commands!

1.8 File name completion with tab

To autocomplete remainder of file name instead of typing it all in:

  • cat h…(press tab)
    • cat history
  • prevents typos and saves time

1.9 Files: moving files from one filename to another

moving “mv” command

Syntax: mv sourcefilename destinationfilename

mv history.txt history_file.txt

ls -l

1.10 Files: copying files from one filename to another

copying “cp” command

Syntax: cp sourcefilename destinationfilename

  1. Change back to the linuxc directory:
cd ~/linuxc
  1. Make a “back up” copy of a file in your working directory:
cp history_file.txt history_bu.txt
  1. Check if the newly copied file is there:
ls

1.11 Copying files between your laptop and the NCGR server

Open FileZilla.

  1. Change the connection from ftp (file transfer protocol) to sftp (ssh file transfer protocol).
  • In the menus, click File:Site Manager.

  • Click on “New Site”.

  • Under protocol, choose “SFTP - SSH File Transfer Protocol.

  • Under host, type “inbre.ncgr.org”.

  • Under host, type “2309”.

  • Put in your username.

  • Click “Connect”.

Note: The first time you connect, you might get a popup about an “unknown host key”. Click the box to “always trust this host” and click “OK”.

Now you should be able to navigate to files on your local machine (left) and on the NCGR server (right). You can drag files between them.

Note: if you create new files they won’t show up until you hit the refresh button in FileZilla (blue and green circular arrows at the top of FileZilla).

Try to download your history file from the NCGR server (history_file.txt) that is in your ~/linuxc directory.

You can right click on the downloaded file (left side of FileZilla) and choose open to open the file on your local computer.

Note: Double-click transfers files instead of opening them.

1.12 Files and directories: removing files is deleting files

removing “rm” command

Syntax: rm [options] filename

rm history_bu.txt

Check that it is gone.

ls -l

1.13 Tool box: How to abort a command/process

Hold “control” key then hit “c” key, then release.

  • Control-key often referred to as CTRL.

Let’s say you type a command and nothing happens; it hangs. This can happen when the syntax doesn’t make sense. Good time for CTRL-c

cat

This should hang because the cat command needs a file name after it. Hit ctrl-c to stop it (you should see the prompt again).

1.15 Head and Tail

The head and tail commands give you the first or last 10 lines of a file, which can be handy for getting a glimpse into the contents of a file.

Grab the beginning of a file.

head covid.fasta

Grab the end of the file.

tail covid.fasta

1.16 The pipe operator

The pipe operator takes the output of one command and puts it as input into a second command.
+ The symbol “|” denotes a pipe

Use the pipe operator to redirect “cat” output to “head”:

cat covid.fasta | head

Note: This is a trivial example as it does the same thing as “head covid.fasta” but you get the point.

1.17 grep

Grep will output the lines from a file that contain a provided expression.

Syntax: grep [options] “expression” filename

grep ">" covid.fasta

Adding the “-c” option counts the number of lines containing a match

  • not the number of matches!
grep -c ">" covid.fasta

The “-v” option reverses the grep search.

grep -v ">" covid.fasta

Use ctrl-c to halt the overflow of output.

We can add in the pipe operator to redirect our output to the “wc” command. The -l parameter limits the wc output to the number of lines.

grep -v ">" covid.fasta | wc -l