Top Banner
Unix Tutorial for FreeSurfer Users Allison Stevens
50

Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

May 24, 2018

Download

Documents

dangtram
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Unix Tutorial for

FreeSurfer Users

Allison Stevens

Page 2: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

What is Unix/Linux?

• An operating system (like Windows and OS X)

•  Linux is the free, modifiable, and redistributable version of Unix

• Why use it?

Page 3: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

What is Unix/Linux?

• An operating system (like Windows and OS X)

•  Linux is the free, modifiable, and redistributable version of Unix

• Why use it? –  freedom to modify and customize –  power to write many scripts with

multiple commands to manage data –  to use computer resources on the network

efficiently, such as clusters

Page 4: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Getting Started

Communicate with operating system through a “shell” or terminal window.

For course-provided Linux computers: Double click Terminal icon on Desktop For Macs: Applications > Utilities > XQuartz (double click) Applications > Utilities > Terminal

Page 5: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Warm Up

Type: and hit enter.

date

Page 6: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Warm Up

Type: and hit enter. Should see

date Mon Apr 6 8:05:24 EDT 2009

Page 7: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Warm Up

Type: and hit enter. Should see

Type: and hit enter.

date Mon Apr 6 8:05:24 EDT 2009

cal

Page 8: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Warm Up

Type: and hit enter. Should see

Type: and hit enter. Should see

date Mon Apr 6 8:05:24 EDT 2009

cal April 2009 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Page 9: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directories

• Unix uses a hierarchical file system (think folders in Windows)

Page 10: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directories

• Unix uses a hierarchical file system (think folders in Windows)

Home is like “My Computer”

Page 11: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directories

• Unix uses a hierarchical file system (think folders in Windows)

Home is like “My Computer”

Like “My Documents”

Page 12: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directories

• Unix uses a hierarchical file system (think folders in Windows) Home is like

“My Computer”

Like “My Documents”

Like “My Photos”

Page 13: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directories

• Unix uses a hierarchical file system (think folders in Windows) Home is like

“My Computer”

Like “My Documents”

Like “My Photos”

picture.jpg

Page 14: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Location

path: /MyComputer/MyDocuments/MyPhotos

Type: and hit enter. Should see

shows “present working directory” or current

location as a path

pwd

/home/nmrclass

/Users/YourName

OR

Page 15: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Opening a Directory

• Not double clicking •  Type command to “open”

•  Commands to open files will differ

Page 16: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Navigating Directories

“change directory”: move into a folder “list”: see contents of directory

ls

cd __

ls __

Page 17: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Navigating Directories

“change directory”: move into a folder “list”: see contents of directory

ls

cd __

ls __

Desktop matlab tmp TUTORIAL_DATA

Page 18: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Anatomy of a Command

command -option1 –option2 file

command - -help

Page 19: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Anatomy of a Command

command -option1 –option2 file

command - -help

ls --help

Try:

or man ls

Page 20: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directory Contents

• List contents of directory you are in lists names of directories/files ls

ls -lrt

ls -l

ls -a

Page 21: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directory Contents

• List contents of directory you are in lists names of directories/files lists hidden files too

.cshrc

.bashrc

.alias

ls

ls -lrt

ls -l

ls -a

Page 22: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directory Contents

• List contents of directory you are in lists names of directories/files lists hidden files too lists file details

drwxrwx---

user group others

ls

ls -lrt

ls -l

ls -a

Page 23: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Directory Contents

• List contents of directory you are in lists names of directories/files lists hidden files too lists file details lists recent files last

ls

ls -lrt

ls -l

ls -a

Page 24: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Save Some Time

Filename Completion

hit Tab key should see hit enter

History

hit key should see

ls Des

ls Desktop

ls Desktop

Page 25: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Changing Directories

makes a new directory “practice” changes to directory “practice”

mkdir practice

cd practice

ls -lrt

pwd

ls

pwd

/home/nmrclass

/home/nmrclass/practice

should see

should see

should see Nothing!

Page 26: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Changing Directories

Page 27: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Changing Directories mkdir stuff

ls

makes folder “stuff” inside practice

should see “stuff”

Page 28: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Using an Editor

If using a Mac: Type: I could write a script. File > Save (Buffer) File > Exit emacs

should see “mynotes.txt”

emacs mynotes.txt open -e mynotes.txt

ls

Format > Make plain text File > Save

Page 29: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Using an Editor

If using a Mac: Type: I could write a script. File > Save (Buffer) File > Exit gedit

should see “mynotes.txt”

Other Editors: pico

gedit mynotes.txt

ls

Format > Make plain text File > Save

open -e

Page 30: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Using an Editor

Ctrl+C Returns prompt

& Runs program in background

gedit error.log &

Page 31: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Using an Editor

Page 32: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Copying files

ls

cp --help

cp mynotes.txt stuff

cd stuff

more mynotes.txt

learn all the options or “arguments”

is the copy command cp

Page 33: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Copying files

ls

cp --help

cp mynotes.txt stuff

cd stuff

less mynotes.txt

learn all the options or “arguments”

is the copy command cp

Page 34: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Changing Directories

shows one directory up

ls ..

pwd /home/nmrclass/practice/stuff

ls ../.. goes up two! cd ..

should see

cd ../..

can also do (but don’t right now):on

Page 35: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Copying / Moving files

cp mynotes.txt myothernotes.txt

Could also use do:

mv myothernotes.txt hernotes.txt

mv hernotes.txt ..

Page 36: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Removing Files

rm mynotes.txt

ls

pwd should be in “stuff”

ls

Page 37: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Things to know

•  Case sensitive •  Does not like spaces in file names

(e.g. filename.txt vs. file name.txt) •  Ctrl+c kills a process & brings back command prompt •  Type ‘q’ to quit the program ‘less’ •  Highlight & middle click to copy & paste •  Use ‘&’ to open a program in the background

Cannot open a 2nd program if do not have a command prompt

Page 38: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Review

• no double clicking • mkdir •  ls • cd • pwd • emacs, gedit, vi, pico • cp • rm

Page 39: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Using FreeSurfer

With FreeSurfer, certain variables must be set in order to use it correctly:

FREESURFER_HOME

SUBJECTS_DIR

tell Operating System where FreeSurfer is

tell FreeSurfer where data is

Page 40: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Required Variables

• To use FreeSurfer you’ll have to do:

setenv FREESURFER_HOME /home/apps/freesurfer

source $FREESURFER_HOME/SetUpFreeSurfer.csh

tell Operating System where FreeSurfer is

source this script to get your computer ready to use FreeSurfer (sources other scripts & sets other variables)

setenv SUBJECTS_DIR /path/to/data

Page 41: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Required Variables

• To use FreeSurfer you’ll have to do:

export FREESURFER_HOME=/home/apps/freesurfer

source $FREESURFER_HOME/SetUpFreeSurfer.csh

tell Operating System where FreeSurfer is

source this script to get your computer ready to use FreeSurfer (sources other scripts & sets other variables)

export SUBJECTS_DIR=/path/to/data

Page 42: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Required Variables

To go to location of your data:

$ means take the value of the variable

cd $SUBJECTS_DIR

setenv SUBJECTS_DIR /path/to/data

Page 43: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Required Variables

To go to location of your data:

$ means take the value of the variable

cd $SUBJECTS_DIR aka

cd /path/to/data

setenv SUBJECTS_DIR /path/to/data

Page 44: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

$

How ‘echo’ works: To set a variable:

To check what a variable is set to: echo $TEST_VARIABLE

setenv TEST_VARIABLE yourfirstname

echo Allison is cool.

Page 45: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Required Variables

With FreeSurfer, certain variables must be set in order to use it correctly:

FREESURFER_HOME

SUBJECTS_DIR

tell Operating System where FreeSurfer is

tell FreeSurfer where data is

echo $FREESURFER_HOME

echo $SUBJECTS_DIR

To check variables

Page 46: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

More Help

http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/CommandLineNavigation

Links on Wiki under “Unix Tutorial” Glossary of Unix commands

Page 47: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

More Help

•  UNIX Tutorial For Beginners: http://www.ee.surrey.ac.uk/Teaching/Unix/

•  Linux in a Nutshell:

http://docstore.mik.ua/orelly/linux/lnut/ch01_01.htm •  UNIX Cheat Sheet:

http://tux.cs.unlv.edu/refs/linux_commands.html

•  Command Line Tutorial: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/CommandLineNavigation

Page 48: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

The End

Good Luck!

Page 49: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

Intro to FreeSurfer Jargon

voxel surface volume vertex surface-based recon cortical, subcortical parcellation/segmentation registration, morph, deform, transforms

(computing vs. resampling)

Page 50: Unix Tutorial for FreeSurfer Users//surfer.nmr.mgh.harvard.edu/ fswiki/FsTutorial/ CommandLineNavigation Links on Wiki under “Unix Tutorial” Glossary of Unix commands . More Help

More Help

alias e emacs man alias ls file* ! lists file1, file2, file3 ls file[12] ! lists file1 and file2 but not file3 command >>& file.txt ! save output to screen and errors

in text file