Unix for Neuroimagers: Part 2 (More commands, and the PATH variable)

After you have gotten comfortable and (emotionally) intimate with the basic Unix commands for navigating your environment and listing contents of directories, the other essential tools you will need, if you are using a package like FSL, is a working understanding of the PATH variable. It is not critical that you know how to set the path on your own, but it helps to know conceptually what it does, and why the FSL and AFNI people require you to amend it in certain ways when installing their software.

The PATH variable (Most Unix variables are in all upper case; by the way, now might be the time to define what a variable is; it is an object storing a value, such as a number or a word) is a pointer to specific directories in your directory tree, and allows you to execute the programs and binaries within that directory. For example, almost all of the Unix commands you use are in the /bin folder; instead of having to navigate to the /bin folder to execute a certain command, or explicitly type out the full path to a directory where a command is located, the PATH variable will allow you to execute that command from any directory in your environment. For example, typing the command "echo $PATH" in the terminal might return the following list of directories in my PATH (echo is a command to return the output of a command to the command line, and the dollar sign in $PATH signals that PATH is a variable):
Note that each directory is separated by a colon. This is a Unix convention, and may take some time to adjust your pitiful human eyes to this.

In this example, all of my FSL binaries (or commands, or executables; I use the words interchangeably, although there are differences in meaning) are located in the directory /usr/local/fsl/bin, while all of my AFNI binaries are located in /Users/andrewjahn/abin. Having these directories listed in my path saves me from having to type the entire path to the command. For example, instead of typing:
I can just type:
From anywhere in my Unix environment, and the afni command will execute.

A couple of other important topics covered in this tutorial are startup scripts and sourcing. Startup scripts refer to a series of commands that is executed every time you open up a new terminal or a new shell. In this example, I modify the a startup script called .cshrc (CSH stands for the c-shell; RC stands for run command), and add the lines given by the FSL installation instructions. You can add anything else in there as well, including aliases (i.e., alternate and easier to remember names for more complex commands). The point is that everything within this file will be run each time you begin a new Unix session.

The source command is not strictly necessary, but saves you the time from having to close a session and begin a new one in order to execute everything inside the startup file. Just typing in "source .cshrc" from your home directory is enough to execute the file.

Also uploaded recently is another tutorial covering the basic remove and remove directory commands, as well as how to interact with text files from the Unix command line. I mention it in the video, but I will also restate it here: The rm command is extremely powerful, and removes things forever. That's "forever" with an "f". It does not send them to some Recycling Bin or Trash Bin or anything fruity like that; those files are straight up gone, which means that you better know what you are doing before you use it. This is mostly a word of warning to beginning Unix users, although I have torched innumerable datasets in my day through carelessness, maliciousness, or that fitful combination of both that sometimes seizes me in sudden bursts of anti-fMRI fury.