Differences between revisions 25 and 26
Deletions are marked like this. Additions are marked like this.
Line 52: Line 52:
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! 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! {{{ ls }}}, as you may guess is short for "list".
Line 58: Line 58:
One of the directories you can go to now is called {{{ tutorial_data }}} lets enter that directory and explore what is inside. One of the directories you can go to now is called "tutorial_data" lets enter that directory and explore what is inside.
Line 82: Line 82:
{{{ 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! {{{ cd .. }}} will take you out of the directory you are in, and into the directory that directory is in. Let's go two more directories up, so type in {{{ cd .. }}} again, hit enter. Now type in {{{ cd .. }}} one more time and hit enter.
Line 84: Line 84:

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. Spend some time now exploring these directories with {{{ cd }}} {{{ ls }}} and {{{ cd .. }}}
type in {{{ pwd }}} and press enter to see where you are, you should be in "/home/nmrclass", your home directory we started in. If not, just type in {{{ cd ~ }}} and hit enter. {{{ cd ~ }}} will always send you home.
Line 88: Line 87:

Because you've spent some time exploring on your own, let's get you back to a particular spot. Type in {{{ cd ~ }}} (Hint, the ~ is the key to the left of the number 1 and q keys ). That will take you back to the directory we started in when you first opened the terminal. Take a look at the files in that directory again.
Line 95: Line 92:
Press tab and the terminal will fill in what it thinks you will type - kind of like autocomplete on your phone or browser. It should fill it in with {{{ tutorial_data/ }}} , now enter the directory. Press tab and the terminal will fill in what it thinks you will type - kind of like autocomplete on your phone or browser. It should fill it in with {{{ tutorial_data/ }}} , now enter that directory.
Line 99: Line 96:
Enter {{{ ls }}} again, and the terminal will show you everything in the {{{ tutorial_data }}} directory, use {{{ ls }}} {{{ cd }}} and auto-completion to navigate to {{{ /buckner_data/tutorial_subjs/004/mri }}}
Now fo
r a small challenge: use {{{ ls }}}, {{{ cd }}} and auto-completion to navigate to " /buckner_data/tutorial_subjs/004/mri "

Unix Tutorial

Who this tutorial is for:

People with little to no Unix experience, or with some experience but looking for a 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:

  • Knowing how to navigate around Unix directories
  • Knowing how to launch programs
  • Knowing how to quickly peek into the contents of a text document
  • Knowing how to access variables

What is a Unix terminal?

A 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 about Unix terminals?

Throughout this course you will be using the Unix terminal to interact with FreeSurfer and access data. Many computer programs for scientific use are designed to be operated through the terminal. By the end of this tutorial you will have familiarity with finding data and launching programs through the terminal.

How do I use the terminal?

Getting Started

TerminalIcon.png 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.

OnTopCropped.png

Whenever you launch the terminal, you can imagine it as if you are getting onto a bike. A bike has a location, and can travel to other locations. The terminal also has a location, and you can navigate it to other locations.

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?".

pwd.png

Looking at files

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  / . You can think of directories as "places", "locations", or "folders".

folders.png

  • Files - anything that doesn't end in a  /  these can be documents, pictures, programs, dicoms... any data!

files.png

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!  ls , as you may guess is short for "list".

You find data in the Unix terminal by looking through directories, all data belongs inside a directory somewhere on the computer. If you use Windows or OSX you might know the term "folder", directories are the same concept.

One of the directories you can go to now 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:

  1. Type in  ls  to see what is in this directory

  2. 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, try to do it on your own, but look below if you need help.

Want to know the answer? Click and drag to highlight and reveal the text below.

cd dicoms

Once inside dicoms, enter a command to see what data is inside. Try to do it on your own, but look below if you need help.

Want to know the answer? Click and drag to highlight and reveal the text below.

ls

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 that FreeSurfer data, first, leave the dicoms directory. How do you do that? Type in  cd .. 

 cd ..  will take you out of the directory you are in, and into the directory that directory is in. Let's go two more directories up, so type in  cd ..  again, hit enter. Now type in  cd ..  one more time and hit enter.

type in  pwd  and press enter to see where you are, you should be in "/home/nmrclass", your home directory we started in. If not, just type in  cd ~  and hit enter.  cd ~  will always send you home.

Getting around quicker

Now type in only  cd tu  and don't press enter.

pretab.png

Press tab and the terminal will fill in what it thinks you will type - kind of like autocomplete on your phone or browser. It should fill it in with  tutorial_data/  , now enter that directory.

posttab.png

Now for a small challenge: use  ls ,  cd  and auto-completion to navigate to " /buckner_data/tutorial_subjs/004/mri "

Take a look at the files inside, these are freesurfer volumes. You will learn more about these later - but for now lets examine one.

Launching programs

Usually you can only access files and programs inside the directory the terminal is in - but we set up your computer so that you can launch FreeView (a tool to look at FreeSurfer data) anywhere. Enter this command to launch FreeView and examine some data ( you will want to make sure you are in the directory you were asked to go to last challenge, if you are not you can use this command to get there  cd /home/nmrclass/tutorial_data/buckner_data/tutorial_subjs/004/mri  )

 freeview -v orig.mgz 

fvpreview.png

Usually, after you type in a program name, you add something called arguments at the end like  -v orig.mgz . In this case the argument opened the orig.mgz volume.

Close your FreeView window (press on the world  file  in the top left, then  exit  ).

Now, an important experiment for you to try. Leave the directory you are in by typing  cd ..  . Now, try to open the first volume we opened by typing in  freeview -v orig.mgz  . You will get an error! That is expected.

failed.png

The error is because there is no orig.mgz in the directory you are in, the orig.mgz is in a different directory. Orig.mgz is actually in the mri/ directory inside the directory we are in right now, there are 2 different ways we can open it again.

See if you can figure out how to open up the orig.mgz volume again.

Were you successful? There are a couple of different ways to have done it:

  •  cd mri  then  freeview -v orig.mgz 

  •  freeview -v mri/orig.mgz 

There are often many ways to accomplish anything with the Unix Terminal, so if you ever see something done in a way you don't understand that is okay! The terminal is something you never stop learning about.

Accessing Variables

Moving in and out of directories can be exhausting! What if there was a way to tell your terminal to remember certain directories - like bookmarks in your web browser? There is. You can store directories in variables. Let's use a variable we already set up for you.

type in  cd $TUTORIAL_DATA  (hint, you can use the tab auto-complete here!)

You are back in your tutorial data directory! You can use this if you ever get lost in all of your directories. If you ever just want to take a peek to see what is inside a variable you can use  echo  type in  echo $TUTORIAL_DATA  to see that the variable is holding the path to your tutorial data directory. And if you type in  pwd  you will see that they match, because you are in the tutorial data now!

Whenever you open your terminal, we have it set up so a bunch of handy variables are set up for you. You can close your terminal now and re-open it to see, or just look at the screenshot below:

vars.png

At the start of most tutorials you will be asked to set the SUBJECTS_DIR variable. FreeSurfer checks the SUBJECTS_DIR to find data, so we change that variable to point to whatever directory has the subject data we want FreeSurfer to process.

Other useful info

Have extra time? Play some Terminus! It's a game that will help you get very comfortable with the  cd  and  ls  commands, along with how paths work.

http://web.mit.edu/mprat/Public/web/Terminus/Web/main.html

UnixTutorial (last edited 2019-09-23 07:42:40 by MatthewLarrabee)