Difference between revisions of "Computer lab introduction"

From MolEvol
Line 1: Line 1:
''"On the other side of the screen, it all looks so easy."'' (TRON, 1982)
''"On the other side of the screen, it all looks so easy."'' (TRON, 1982)
[https://molevol.mbl.edu/images/1/1a/Computer_Lab_intro_2015.pdf Slides here]
[https://molevol.mbl.edu/images/1/1b/Computer_Lab_intro.pdf Slides here]

Revision as of 10:38, 17 July 2016

"On the other side of the screen, it all looks so easy." (TRON, 1982)

Slides here


By the end of this introduction, you should be able to:

  • Log in to the class cluster.
  • Navigate and understand the directory structure.
  • Create and edit files and directories on the cluster.
  • Move files to the cluster.

Ask for help if any of these things aren't working by the end!

WiFi Login

To log on to the MBL wireless choose the MBL-REGISTER from the wireless list. Your username is your initials followed by the 5 digit number on the side of your identification card. Your password is the same. E.g. if your name is Jane Bloggs and the your card has the number 12345 on the side then your login details are:

username: jb12345
password: jb12345

Some people have been having trouble, if it isn't working find or email Emily Jane ejmctavish@gmail.com


Please download and install the following programs:

After you have installed Notepad++, open it. Go to Settings, Preferences, New Document, and set the line endings to Unix.

Remote computer access software

We will use Secure Shell (SSH) and sFTP to connect to the servers. The servers are powerful computers where we can run the programs much faster than would be possible on your laptop. In order to access these you need to log in to your assigned server


SSH stands for "Secure Shell." These are programs that provide a Unix shell so that one can enter commands and log onto other computers (i.e., those on the server where we will be doing our analyses).

You must be on the MBL register internet or this will not work

SSH on Linux and Mac Os X

First, open a terminal window:

  • Linux: Konsole (KDE), gnome-terminal (GNOME)
  • Mac: Terminal (in /Applications/Utilities)

First we want to log on to the class servers.
In the following command replace username and servername with the user and server name found on the back of your name tag:

ssh username@servername

For example if my username is jbloggs and my server name is class04.jbpc-np.mbl.edu I type:

   ssh jbloggs@class04

It will then ask for your password which is on the back of your card under your username

SSH on Windows

Use PuTTY. To set up SSH on PuTTY Enter your username and servername in the "Host Name or IP Address" field You can find your username and servername on the back of your name tag:


For example if my username is jbloggs and my server name is class02 I type:


Enter a name for this configuration (e.g. MolEvol) where it says "Saved Sessions" and click Save Now you can access the cluster by clicking on that saved session.

PuTTy copy paste tip: PuTTy FAQ

Copy and paste works similarly to the X Window System. You use the left mouse button to select text in the PuTTY window. The act of selection automatically copies the text to the clipboard: there is no need to press Ctrl-Ins or Ctrl-C or anything else. In fact, pressing Ctrl-C will send a Ctrl-C character to the other end of your connection (just like it does the rest of the time), which may have unpleasant effects. The only thing you need to do, to copy text to the clipboard, is to select it.

To paste the clipboard contents into a PuTTY window, by default you click the right mouse button. If you have a three-button mouse and are used to X applications, you can configure pasting to be done by the middle button instead, but this is not the default because most Windows users don't have a middle button at all.

You can also paste by pressing Shift-Ins.


You should have a black screen asking for your password, which is on the back of your card under your username. Type it in. You will not see the letters you are typing.

Changing your password

The first thing to do once you have successfully logged on to a server is to change your password. This is done by typing:


This will prompt you to enter a new password so do so and press the enter key. Next you re-enter the new password and again press enter. It may then ask you for your LDAP password and you should type in your original password given on the back of your card.
Once you have done this every time you ssh in to the server you will use the new password created.

Directory structure

The file systems used by Linux, Mac OS X, and Windows are organized in a hierarchical, multifurcating tree structure. That might sound confusing, but you're used to working with this organization scheme through the Mac Finder or the Windows Explorer--folders (directories) are stored inside other folders, and they in yet other folders. The path through this directory tree can be used to specify the absolute (starting at the root) or relative (to some other directory) location of any given file.

  • NOTE: Regardless of the operating system on your laptop, when you log on to the cluster, you will be on the class machines, and they're all running linux.

Basic Syntax

Unix commands follow the general format of:

command -options target

Not all commands need options (sometimes called flags, and generally preceded by a single or double hyphen ("-" or "--")) or targets, but others require them.

  • For example:
    • cd homedirectory uses the command "cd" (change directory) and the target "homedirectory" to move from the current directory into the subdirectory called "homedirectory"
    • ls -l homedirectory uses the command "ls" (list), the option "-l" for long-list, and the target "homedirectory" to list the contents of homedirectory in the "long list" format, which provides more thorough descriptions than does the regular "ls".

Notes on syntax for directory structure

  • Two dots (..) indicates the parent directory of the present working directory. So, for example, "cd .. will move you back one directory.
  • One dot (.) indicates the present working directory. So, for example, "cd ." will keep you where you are. There are times where the single dot can be more useful than this...
  • The tilde (~) refers to your home directory. On the class machines your home directory is /class/yourusername. You'll also have a unique home directory on your laptop, etc. The tilde is very helpful if you get lost while using the terminal -- just type "cd ~" and you'll be back in your homedirectory.
  • A forward slash (/) by itself or at the start of a path refers to the root of the filing system -- the folder that contains all other folders.
  • NOTE: do not make changes on the class server in the root folder or any shared folders. All your work is to be done in your home directory or a subdirectory.

Some suggestions concerning file and folder names

  • Avoid spaces in script and filenames (use underscores, dots, or hyphens, use "CamelBack" notation). Spaces are used in command line editing to separate options etc so if there is a space in a filename it will mess up the correct running of programs.
  • Do not use "weird" characters (#@!*&^, etc., especially ?, *, \, or /)

Don't Panic

When it all goes south, "control-C" is your friend. It breaks whatever processes are running, and gives you your prompt back. Or, failing that, just close the Terminal and start again.

Helpful navigation

Tab will auto complete text for you.

The up arrow will bring up commands you typed previously.

Intro-to-Unix tutorial


Start by entering


This will print your working directory (the directory you are currently in). You should be in /class/your_login

Next, type:


This lists the contents of your working directory (which is likely empty).
You can also look at the contents of any other directory by supplying the path. For instance,

ls ..

will list the contents of the parent directory that your current directory is in, in this case the class directory.

mkdir is the command to make a directory. Type

mkdir myfolder

to make a new folder called myfolder. Type ls and then enter. It should be listed. We can also use the ls command with flags at this point. Typing

ls -l

will list the contents of the current directory in "long" format which includes information about permissions and file size.

ls -ltr

will list the contents of the current directory in "long" format, and in time (t) reversed (r) order. This makes it easy to see what files are newest.

cd is the command to change directories. We can move into the new folder you made by typing

cd myfolder

You can use pwd to confirm you've moved and are now in a new working directory. You can move back to your home directory by typing cd with no arguments. This is a handy trick if you are lost in the filesystem and want to get home!


Confirm you are in the class directory with pwd. You can move from here to the myfolder directory in your home directory by typing

cd myfolder

Copying, renaming, and moving files

Check what folder you are in using


It should be your myfolder in your home directory. The copy command (cp) is used to copy files to new places. The command basic syntax is cp source_file destination_file First create a file called 'tmp1.txt' in nano and put whatever you want inside of it.

   nano tmp1.txt

Type content there, use Ctrl-X to exit (hold down the control key and type x) Type 'Y' and enter to save your changes.

Use head to look at the contents of that file

  head tmp1.txt

We will now make a copy of tmp1.txt called tmp2.txt by typing:

cp tmp1.txt tmp2.txt

We can also cp a file from the shared directory using absolute and relative paths.

cp /class/shared/testfile.txt .

will copy a file named "testfile.txt" to your current directory but will not change its name. Use ls to verify.
The move command (mv) can be used to move or rename files. The command syntax is mv source destination. Hint: Try just typing the first letter of the file you want to move and pressing the Tab key.

mv testfile.txt example.txt

has the effect of renaming testfile.txt to example.txt. Use


to check. use

  head example.txt

to see its contents.

Use the up arrow to see commands you have typed previously. Great for fixing typos!

We can move this file to the folder we created earlier by by using mv as well.

mv example.txt myfolder/

will move the example.txt file to the parent directory of your current directory. Use ls .. to check.

  • NOTE: Do not move files that are not in your home directory or a subdirectory of this. All files in shared or root folders are to be copied, never moved.

In order to get a file from an online source you can use wget. Type:

wget <URL>

Where the url is the website address of the file you wish to download. For example

wget http://phylo.bio.ku.edu/slides/GarliDemo/molevol2016.txt

Will download the file molevol2016.txt to the directory you are in.

Copy this file to a file named <yourname.txt> (remember! No spaces!)

Edit the statement in the file using nano, to a fact about yourself.

Copy it to the /class/shared/facts directory.

Ask a person next to you their name, and find and read their fact!

For more info on using the unix shell check out Software Carpentry tutorial

Loading pre-installed programs

Many of the programs that you will need for the course are already installed on the class servers. These need to be specifically loaded in for them to work.
For example on the command line type


You should get an error message saying: -bash: garli: command not found
Now type

module load bioware

This should load all the preinstalled programs so that you can access them. Now type garli again and you should see some information on Garli options ending with:
ERROR: could not open file "garli.conf".
Showing that garli is now available for use.
If needed, programs can all be unloaded by typing module unload bioware

Setting up Cyberduck

Creating a bookmark

When you open Cyberduck a screen should appear that has some default connections bookmarked such as Google Docs and Amazon.
Click the '+' button at the BOTTOM LEFT to create a new bookmark (NOT the one with the globe at the top). Here we will put the details of our cluster login and save it so that each time we open Cyberduck we don't have to re-enter the details. Click the dropdown menu that says FTP (file Transfer Protocol) and select SFTP.
Create a nickname for this bookmark. For example mine is called 'MBL cluster'.
In 'server' write the class number of the server you were given. For example, I am emctavish@class04.jbpc-np.mbl.edu so I put class04.jbpc-np.mbl.edu in here.
In the username box place the username you were given. This is likely your first initial and your last name. For example mine is emctavish.
Once all these details are entered close that screen. (e.g. on a mac click the red circle or on windows click the X).
A new bookmark should have appeared named whatever you set as the nickname. Double click on this.
Cyberduck should ask you for the password. Type in the password you changed it to earlier. There should be a button asking for you to 'add to your keychain' or something similar. Make sure this box is ticked. Once done, click to connect.
This may connect you directly to the cluster. If not double click on the bookmark again.
You now should see your home directory on the cluster. You should see the file "yourname.txt" that we created earlier.

Navigating the cluster on Cyberduck and transferring files

Navigating through the class cluster in cyberduck is easy.
Double click on a folder to open that folder.
Above the window that lists files there should be your path. For example when I login my path shows '/class/emctavish'. This tells me where I am on the cluster right now. If you click this dropdown menu you can see each folder you are in. For example when I click on the dropdown I have a line that says /class/emctavish, one that says /class and one that just says /. Clicking on any of these will allow you to navigate to that folder. If you get lost in folders you can click this dropdown and select /class/username (where username is your own username) and this will bring you to your home directory.
An alternative way to go to a specific folder is click the 'Go' menu at the top of Cyberduck and click 'Go to folder'. Here you can write the full path and go to a specific folder. For example, if you are logged in to the cluster through a terminal/putty you can type 'pwd' and then copy that path into the 'go to folder' box and now Cyberduck will be in the same folder as your terminal window.

There are two ways to download files from the class cluster to your computer.
1.If you double click on a file name, this file will be automatically downloaded to your default download folder. A transfer window should open up when you double click on a file. At the bottom there will be a line that starts 'local file'. This is the location of that downloaded file on your own computer
2. An easier way to get files both to and from the class cluster through Cyberduck is through drag and drop. If you have an open finder window (mac) or explorer window (windows) you can click and drag a file from the Cyberduck window to the finder/explorer window directly. You also can do this in the reverse (drag a file from finder/explorer to Cyberduck) to place a file on the cluster in that folder.

Using Cyberduck for remote editing

Instead of using nano or similar to edit files on the class cluster you can use a GUI text editor like TextWrangler through Cyberduck.
In cyberduck click 'File'->'Preferences' on a Mac or 'Edit'->'Preferences' on Windows.
Click the 'Editor' button.
There should be a dropdown menu where you can select a text editor. Select TextWrangler on a Mac, Notepad++ on Windows.
Close this window.
Now when you single click on a file in Cyberduck, a 'Edit' button with the icon for the editor you selected should appear in the top right corner. Click this button to open that file in the editor. Now you can edit the file on the cluster without downloading to your local computer. When you save this file it will be automatically updated on the class cluster.

Short Cyber Duck Exercise

The easiest way to transfer files using CyberDuck is with drag-and-drop. Try to drag a file from your desktop (or another folder of your choosing) from the CyberDuck window. This method allows you to choose unique destinations for each file you transfer.

In CyberDuck, double click example.txt your 'myfolder' on the cluster. To where does this file download? CyberDuck also allows for more permanent modification to how files are downloaded, you can set automatic download locations. If you want to change this, under Edit -> Preferences -> Transfers, you can edit this.

Lastly: Right clicking (Ctrl click on a Mac) will allow you to select Download to or Download As. This will allow you to choose a location, and if you choose, a new file name for the file.

These methods will all work to get files from the cluster to your computer, and each have their own benefits. Generally, you will be fine using any of them throughout the course.

Make a folder on your computer to hold all of your lab materials from this course!

SCP is a good alternative to Cyberduck for linux and Mac's

There are two places you may need to get files on to the class server from: your own computer or an online source
In order to get files from your computer to the server open a terminal window and navigate to the folder on your computer using the commands like cd. Once in the folder containing the file you want to upload you type

scp filename username@classServername:~

e.g. just like cp, the format is scp <from> <to>

To get files from your computer to the cluster:

   scp text.txt emctavish@class01:/class/emctavish

To get files from the cluster to your computer:

   scp emctavish@class01:/class/emctavish/testfile.txt .

Accessing the cluster from outside MBL

Follow the same instructions from above except: replace the server address (@class07.jbpc-nb.mbl.edu) with @class.mbl.edu and the once on the cluster use ssh class07 (or whatever your appropriate node is), and run your analyses there.

From cyberduck, follow the instructions as above using @class.mbl.edu. All your files on the cluster will be synced to there.

It will be available until Sept 15, but go easy on it next week because the STAMPs course will be using it.

Useful links

The following table contains a list of commands that will allow us to navigate through the directory structure. The entries are linked to their Wikipedia pages, which contain very useful examples.

Some basic commands
Linux/Mac Description Syntax (Linux/Mac)
pwd print working directory pwd
ls list directory contents ls
history display command history history
cd change directory cd directory_name
mkdir make directory mkdir directory_name
cp copy files cp original_filename copied_filename
mv move files (the same as rename files) mv original_filename moved_filename
clear clear the screen clear
exit quit command line exit
' ' Ctrl-E Go to the end of line
' ' Ctrl-A Go to the beginning of line