Who this tutorial is for:
People with little to no Unix experience, or with some experience but looking for a Unix basics refresher.
What are the goals of this tutorial:
To let the student practice the unix skills and concepts needed to enjoy this course. The skills include:
- Understanding the unix file system
- Understanding how to navigate the unix file system with cd and ls
- Understanding that some information can be accessed anywhere via PATH
- Understanding how to reorient yourself when lost
What is a Unix terminal?
The terminal is a way for you to interact with your computer - just like you interact with your phone through the touch screen or your laptop through the track pad. The terminal lets you interact with your computer through typed in commands.
Why learn Unix?
Throughout this course you will be using the unix terminal to interact with FreeSurfer and FreeView. Writing programs that operate through the terminal lets the programmer focus entirely on making powerful and functional software without spending work hours designing and debugging a clickable interface. But stay tuned - more graphical interaction is coming for FreeSurfer in the future! But many users find the terminal to be the fastest way to operate a computer once they get the hang of it.
How do I use the terminal?
Let's get this tutorial started.
Click the terminal icon on the left side of your screen to launch the terminal.
A window will pop open on the screen, before we start typing into it it would be good to adjust the window to be easier to work with. Right click on the bar on the top of the window, then select the "Always On Top" option. That will keep the window in view while you navigate this tutorial. You can also move the window by holding left click on that top bar and moving the window, or resize it by holding left click on the corners.
Whenever you launch the terminal, you can imagine it as if you are getting in your car. You car has a location, and you drive your car around to steer it from location to location to get around the world. The terminal also has a location, and “steer” it by typing in commands.
To see where you are, type in pwd and press enter. The terminal will print out where you are, locations in Unix are called "directories". pwd is short for "Print Working Directory", it prints out where you are. This is like asking your GPS "Where am I?".
To see what data is in this directory, type in ls and press enter.
You will see a list of 2 different things:
Directories - these are the items that end with / .
Files - anything that doesn't end in a / these can be documents, pictures, programs, dicoms... any data!
You will use ls a lot to take a look at where to go next while navigating the terminal, I probably use ls 100s of times a day!
One of the directories is called tutorial_data lets enter that directory and explore what is inside.
Type cd tutorial_data and press enter
Now we are in the tutorial_data directory, try two things to explore:
Type in ls to see what is in this directory
- Type in pwd to see what our working directory is now
Enter the practice_with_data directory with cd practice_with_data
Enter ls to see whats inside. There should be 2 directories. Enter the dicoms directory now, I won't tell you how, but I'm sure you can do it!
Once inside dicoms, enter a command to see what data is inside. I won't say how but you know how!
What you see is a list of data taken from a scan session, FreeSurfer takes this data and turns it into a whole lot of useful new data like 3d surfaces of brains. Let's take a look at some of thar FreeSurfer data, first, leave the dicom directory. How do you do that? Type in
cd .. will take you out of the directory you are in, and into the directory that directory is in. Type ls again to see where you can go, then go into the Subj001 directory. Hint: Capitalization matters!
Type ls to see whats inside the Subj001 directory - you are looking at a bunch of directories made by FreeSurfer to organize processed subject data! You will spend time during this course learning what all of this data means.
There are different ways to mark the location of objects in the world. Lattitude, Longitude, addresses, landmarks, etc. Locations in the terminal are marked through directories.
It will help if you right click the top of the window then choose always on top.
When you open a terminal it usually takes you to your home directory. Type this into the terminal then press enter
The terminal now lists everything in your home directory. You will see a bunch of folders with different names like “Photos” “Documents”. One of them is “freesurfer” Lets navigate into that folder. Type
And press enter.
Then type ls in again and look at what you see. These are some of the files and folders that make up Freesurfer. There is a lot more to FreeSurfer than just this, inside of those folders ar emore files and folders, and so on and so on. Lets examine the data in one of these files. If you look through the files listed in ls there is one called README, you can peek inside by typing
Press q to leave
Less is a tool in unix that lets you quickly take a peek at files.
Not lets leave the freesurfer directory, you can exit a directory by typing cd.. Do that now
Now lets navigate to the data you will using thorughout the week, type in
Cd lets you change directories, and $TUTORIAL_DATA is a variable we set up earlier which is the directory of all the data you will use in the tutorial. You can take a peek inside what $TUTORIAL_DATA is representing by typing
You will see the address of the tutorial data. Echo doesn’t actually make any changes or move where you are - echo just prints out whatever comes after it.
Lets look at some data, type in cd practice_with_data
Type cd dicoms
This is is a list of discoms taken from an mri scan - you will learn more about this data in a future tutorial.
Navigate out of that directory, with cd ..
Then cd into Subj001
Type ls, the list of directories you see is a typical set of directories created by freesurfer after it runs a set of data through its pipeline.
We are not going to take a look at some of this data with FreeView!
Freeview -v orig.mgz
This is an example of an argument. The creators of FreeView haad to decide a way to let the user choose what kind of file they want to open, and which of that file to open. -v means you want to open a volume, and the name of te volume is orig.mgz
Now there are some tricky things here. For example you types in freeview… but there was no Freeview in that directory! So where did it come from? Before you came to class we set up something called a Path, which is a list of directories Unix will search in whenever you launch a command. So, Freeview is in the path, so Freeview was found even though it wasnt in your current directory. NOTE: Allow user to experiment with this. Orig.mgz was in that directory, so it was found. Close Freeview with the x in the upper right hand corner. Now try something.
Navigate up one directory by typiong in cd..
Type ls to see what is in there
Now type Freeview -v orig.mgz just lke before
You will get an error that the file was not found! That is because orig.mgz was not in the directory you are in. Here is what would have worked, feel free to try.
Freeview -v mri/orig.mgz
A volume is one type of data you use in freesurfer, a surface is anohter. Lets open a surface.
Enter the tutorial_data folder again, either by doing the cd.. Comand a couple of types or typing in cd $TUTORIAL_DATA
You also could have accessed that by typiong cd $TUTORIAL_DATA/buckner_data/tutorial_subjs/good_output/surf but I prefer to go dir by dir.
Type ls and look at allk that data!
Lets open one
Freeview -f lh.pial rh.pial -viewport 3d
-f lets us open surfaces, and -viewport lets us choose what kind of view we want to take. You will get more familiar with these commands as the course goes on.