This is an old revision of the document!
Table of Contents
Getting started with the Mac Terminal
The Mac operating system is a Unix-based on graphical user interface. You can therefore interact with your Mac computer using many (most) of the same commands used in Unix/Linux systems. Many of these commands achieve the same things that you can achieve using 'point and click' methods. For instance, if you wanted to create a new folder on your Mac desktop you could click on your desktop, select File
> New Folder
. But you can also create a new folder using Unix commands in Mac's Terminal.app
(which can be found in Applications/Utilities/Terminal
). This will open a “command line” interface (meaning that you interact with the computer by typing out commands rather than pointing and clicking with your mouse/trackpad). By typing the following commands (press enter/return after each line) you will change the directory of your command-line interface to your desktop and create a new folder entitled “mynewfolder”
cd ~/Desktop mkdir mynewfolder
At this point you are undoubtedly thinking “It was way easier to just use the trackpad, so why would I ever want to use the command-line!?” However, the command-line gives you direct control over many aspects of your computer that would be hard (or impossible) to access via the graphical interface. More importantly for our purposes, we can write our commands into a text file and then tell the computer to read the commands from that file (this file is called a “bash script” because the particular Unix language that we'll be using is called “bash”.) This is great because it means that every time we do whatever task we've “scripted”, we can be certain that we're doing it exactly the same way we did it last time. Moreover, if we need to run the task 100 times (e.g. we want to create 100 new folders), we can just tell the computer to read the bash script 100 times. Imagine creating those same 100 new folders by pointing and clicking!
The majority of what we do in this course will rely on controlling your computer using the command-line. You should therefore dedicate a sufficient amount of time to getting comfortable with basic Terminal/Unix commands and behaviors. There are tons of useful OS X Terminal and Unix tutorials online. I've selected a few below that you can use to get started.
OS X Terminal Tutorials
Unix Tutorials
BASH Tutorials
bash is just one of many different Unix “shells” available. Shells are basically different languages for interacting with your computer. We will use bash because it is common, user-friendly, and the default shell on OS X machines.
Most Frequently Used Linux Commands
To get detailed help of these command, including the options available and how to use them, use
man command_name
or
help command_name
manipulating files/directories
- cd - change the current directory
- ls - list directory contents
- mkdir - make directories
- mv - move (rename) files/directories
- rm - remove files/directories
- cp - copy files/directories
- touch - change file timestamps.
- chmod - change file access permissions
- rsync - faster, flexible replacement for rcp (remote file copy)
- scp - secure copy (remote file copy program)
working with text files
- cat - concatenate files and print on the standard output
- head - output the first part of files
- tail - output the last part of files
- wc - print the number of newlines, words, and bytes in files
- more - a filter for paging through text one screenful at a time
- less - a program similar to more, but more powerful (and user friendly)
- grep - print lines matching a pattern
- diff - find differences between two files
- gvim (vi) - The GUI version of vim - a text editor that is upwards compatible to Vi.
- sed - a stream editor used to perform basic text transformations
- awk - pattern scanning and processing language
working with processes
getting useful information
- man - format and display the manual pages
- help - display helpful information about builtin commands
- date - print or set the system date and time
- locate - find files by name
- find - search for files in a directory hierarchy
- who - show who is logged on
- pwd - print name of current/working directory
- du - estimate file space usage
- df - report filesystem disk space usage
- which - shows the full path of (shell) commands
- history - display the command history list with line numbers
others
- echo - display a line of text
- source - read and execute commands from a file
- alias - prints the list of aliases or define new aliases
- gimp - an image manipulation and paint program
- ssh - a program for logging into a remote machine and for executing commands on a remote machine
- mount/umount - mount and unmount filesystems
- passwd - update a user's authentication tokens (password)
- nohup - run a command immune to hangups, with output to a non-tty
- rdesktop - Remote Desktop Protocol client (connects to windows computers)
- export - export supplied names (variables) to the environment of subsequently executed commands
- crontab - maintain crontab files for individual users (used to execute commands at scheduled time)
Frequently Used Packages/Programs/Scripts
Please see here for more details.
matlab
MATLAB is a numerical computing environment and programming language.
fsl
fsl is a comprehensive library of analysis tools for FMRI, MRI and DTI brain imaging data.
bxh_xcede_tools
eventstats tools are part of this package
bioimagesuite
bioimagesuite is image analysis software suite developed at Yale University.
afni
Analysis of Functional NeuroImages is a set of C programs for processing, analyzing, and displaying FMRI data.
freesurfer
freesurfer is a set of automated tools for reconstruction of the brain’s cortical surface from structural MRI data, and overlay of functional MRI data onto the reconstructed surface.
vmware
virtual machine - run windows on linux
SPM
SPM is a matlab software package used to carry out the construction and assessment of spatially extended statistical processes used to test hypotheses about functional imaging data.
others
- mounty - mount hull directories on your local machine
- hnlconvqa - convert dicom files (from scanner) to nifti format and/or do the QA
Basics of Bash Scripting
examples
This is the script used for ffg05 fsl level 1 analysis. Please note usually a template fsf file is required for each design to run this script. For this specific study, since the design of run 10 is different from that of other runs, two template files are needed. Namely, template_lev1.fsf and template_lev1_run10.fsf for runs 01-09, and run 10, respectively. Higher level fsl analysis can be done in the same manner - make a template fsf for one subject, and then modify that file in a script for other subjects.
This is the script used for ffg05 eventstats individual subject analysis. You will see model.txt (often called es_opts.txt) is required to run this script.
This is the script used for roi analysis of facefam05.
This is the matlab script used to display the facefam05 fsl and eventstas results in showsrs2.