Skip to content

Linux and bash scripting

Mehul Gajwani edited this page May 2, 2024 · 10 revisions

Introduction

Your MASSIVE desktop uses an operating system called Linux, which is a Unix-like operating system. It basically works just like the Windows or Macintosh operating systems that you might be more familiar with, but with a greater emphasis on command line usage than menus for navigation.

This means you’ll want to open what is known as a terminal, where you can run text based commands to open and move files or even run different software programs. Bash is a language used in Linux to write these text based commands.

Opening a Terminal

Once you open a desktop session on MASSIVE, you can open a terminal in a few different ways:

  1. In the application taskbar, you should see a little black square icon. Click this to open a terminal session:

  1. Right-click anywhere on the desktop and click 'Open a Terminal':

  1. If you open the file manager (the "cabinet" icon on the application taskbar), you can open a terminal throught the Right-click menu or through the File menu.

When running software on MASSIVE specifically, you’ll often need to load specific modules before you get started in the terminal you’re currently running.

Modules on MASSIVE

As MASSIVE is a shared system, the permissions you have for installing software are limited. Therefore, you can cannot install software. Instead, some software packages come pre-installed. Theses are called modules. In order to use activate these modules, use module load [module_name] to activate them. You can see the modules you have already loaded using module list and you can remove modules using module unload [module_name] or module purge (all modules).

The Basics: Andy's Brain Book

Before you run any software, you’ll need to be familiar with the basic syntax of bash.

Andy’s Brain Book provides an excellent introduction to Unix through a neuroimaging lens. We suggest using this to familiarise yourself with Linux/bash. See the intro here.

  • Lessons 1-4 will cover general commands for navigating file systems and directory trees.

  • Lessons 5-6 will cover for loops and if else statements (even if you’re familiar with these operations in another language, the syntax can still vary in bash).

  • Lessons 7-9 will cover writing and running scripts that will allow you to interact with your data, run your analyses, or anything else you wish to do with your code


Because of the way MASSIVE is set up, there are a few things you will have to do slightly differently when following this tutorial on MASSIVE.


Lesson 2

  • Right-click on the desktop > ‘Create a File’ > name it ‘myFile.txt’
  • Right-click on the desktop again > ‘Open a Terminal’
  • Then follow the instructions using ls, cp, mv, rm
  • Alternatively, you can use the text editor in MASSIVE by going to Applications > Full List of Apps > gedit

Lesson 4

  • You don't need to install or setup FSL
  • Instead, open a terminal session and run the following and look at the output:
module list
module load fsl
module list
  • Replace cat .bashrc with cat ~/.bashrc
  • You can skip the parts referring to tcsh (an alternative bash shell)

Lesson 7

  • You can't install any applications on MASSIVE. We suggest using the text editor in Applications > Accessories > Text Editor:

Clone this wiki locally