Ocean Biogeochemistry Lab
| home | people | research | courses | facilities

Home > Courses > Satellite Remote Sensing > Lab Notes > Lab Notes 2

Lab Notes 2: Introduction to Unix

Logging into Mac computer from A65 PCs:
Recall from last time that in order to access SeaDAS, we must log into Mac OS X, not Windows. Remember to restart your computer, and hold the alt/option key until you are prompted to log into 'Mac' or 'Windows', and choose Mac.
Now log in with your sunet id and password.

SeaDAS:

Most of the satellite data and image processing will be done using the program SeaDAS, which you can access from a Terminal window (the black, square icon at the bottom of your screen). Terminal is a UNIX system, and UNIX has its own set of commands to move around and access data.

Moving around in UNIX:
The filesystem on unix machines is organized in different directories ('folders'). Moving around these folders is no different than moving around a directory tree on your mac or PC, except that instead of double-clicking on folders, you have to type in commands.
When you first open a terminal window, you will be in your home directory (A65pc:/Users/(your sunet id)).
You can see your current directory, and the 'path' to get there, at any time by typing the command pwd.
The command ls will show you what folders are in your home directory. Note that it's just like opening the 'finder' window typical of Macs: you have your 'Desktop' folder, your 'Documents' folder, and so on.

At the start of the UNIX directory tree is the root (/) directory, and from there directories and sub-directories branch out.
To change directories you issue the command cd followed by the (sub)directory. So, to go to the root directory (/) you have to type: cd /
There are several ways to go back to your home directory:

  1. You can type either cd /Users/(your sunet id)
    (note that once you've typed cd /U, pressing the 'tab' key will autocomplete the first word)
  2. You can type cd /Users followed by cd (your sunet id), or
  3. Typing cd alone will bring you back to your home directory at any time

Note that sometimes the directory (path) starts with a '/' and other times it doesn't. The difference is that if the path is preceded by '/' you use the absolute path (starting from the root directory), otherwise it is the relative path (starting from the current directory). To get to your home directory, using cd /Users/(your sunet id) will work from anywhere, while cd Users/(your sunet id) will only work when you are in the root (/) directory.

To go up (backwards) 1 level you type 'cd ..'. So if you were at /Users/(your sunet id)/Documents/, this command will bring you to /Users/(your sunet id)/ (i.e. your home directory). Similarly, if you would have typed cd ../Desktop you would have ended up in /Users/(your sunet id)/Desktop/.

Note that unix is very sensitive to dots, capitals, spaces and any symbols.

Basic UNIX commands:
Some of the commands you will use while managing your satellite data files are:

ls, this will give you a listing of all entries in the current directory. Try this in your home directory. If you want more information, like file size, date last modified, check if it is a directory or a file, etc., use ls -al. When the listing is rolling off your screen you can 'pipe' (|) the list command to more: ls -al | more. Then the listing will pause after each screen. Press the spacebar to see the next page or return for the next line.

mkdir, You can organize your files by putting them in different directories. The command for making a new directory is mkdir followed by the name you want to give it. Example: try making your own sub-directory within your home directory. Typing 'mkdir nadir' will make a subdirectory called 'nadir' within the current directory. You can see it using the ls command. To move to that directory you have to type: cd nadir.

***
You can save class data to your own 'Documents' folder on your network space. This folder will be accessible from any of the other a65 computers you log into. Try moving to your Documents folder now with the commands we've learned. What is the path? What is in your Documents folder?
Now try making a new directory within your Documents folder to hold class data.

***

cp, mv  and rm are commands for copying, moving and deleting (removing) files respectively. If the file to be copied is in your current directory, the syntax (i.e. format) of cp is:
cp <filename>  <to this directory> 
Example: if you are in /Volumes/a65classdata/EESS141/seawifs and you want to copy the file 'seawifs.txt' to your home directory 'johnny' (i.e. /Users/johnny) type:
cp seawifs.txt /Users/johnny

If the file is located in another directory and you want to copy it to directory where you currently are:
cp <that directory/><filename>  <This directory>

Example: If you wanted to accomplish the same task as before, but you were currently in your home directory, you would type:
cp /Volumes/a65classdata/EESS141/seawifs/seawifs.txt /Users/johnny

-or-

cp /Volumes/a65classdata/EESS141/seawifs/seawifs.txt .
where '.' means the current directory. More info is at hand by looking at the manual pages. To check out the manual pages of cp, type: man cp. To exit the manual page, type q.

Take a look around the EESS141 folder in a65classdata, and look at the complicated names of the satellite files. Now try copying one of these to your own class data folder.

mv  works similar as cp, with the difference that the original file will be deleted.
rm is easy to use, maybe too easy. Syntax:  rm seawifs.txt  to delete the file seawifs.txt. Once the file is removed it is gone forever. There is no recycle or trash bin as on a PC or Mac! You can also use 'wildcards' to remove/move or copy more then one file at once. For example rm s* will remove all files starting with 's'. Or rm * will remove all files! Directories cannot be removed with the rm command, use rmdir instead (e.g. rmdir johnny). You can use wildcards with other commands as well. Example:cp *s /Users/johnny will copy all files ending with an 's' to the johnny directory, or ls *s* will list all files with an 's' in the name.

Some other useful commands:

df will give a list with how much free disk space there is left on the disks/partitions. When you type df /Users/(your sunet id)/Documents you will see how much is used and/or available to place new ocean color files on your personal network space.

compress: When you finish working with large data files it is good practice to compress them so they take up less space on the shared disks. Three programs can be used: compress, gzip or bzip2. If you type compress seawifs.txt the file seawifs.txt in its compressed form will have a '.Z' extension, like seawifs.txt.Z. For gzip the extension added is '.gz' and bzip2 '.bz2'. Satellite data ordered will normally be in a compressed format. If it has the .Z extension you can use uncompress to uncompress it, if it has the .gz extension use gunzip, and if it has the .bz2 extension, use bunzip2.

Renaming files can be done with the mv (move) command, e.g. if you want to change the filename final_repport into final_report, type:
mv final_repport final_report
. Note that unix doesn't like spaces or other weird characters in filenames.

Command recall: Use up-arrow or down-arrow to browse to a previously issued command. If you have made a typo in a long command, just use the up-arrow and then left-arrow to correct the typo.

With the command history you can see a listing of recent commands. Type !23 to reissue the 23rd command on that list.

copying & pasting
It is a pain to type long filenames like 'S2000295203345.L2_GAC.Z'. In Unix it is easy to copy and paste instead. Highlight the filename with the left mousebutton. Type command + c to copy the text, then command + v to paste it where your cursor currently sits.

want more?
To learn more about Unix, Phil Farrell (Earth Sciences Computer Systems Manager) has compiled some excellent pages on Using Unix. See esp. the sections on Using the Shell and File Manipulation.

Logging into Icy:
In order to store files and use SeaDAS, we have to log into our lab's server, called 'Icy'. This server is stored next door. Our server, like many servers, doesn't have a graphical user interface (GUI) like a normal desktop or laptop computer, so the only way to operate it is through UNIX commands!
On your Terminal window, type 'ssh -Y eess141@icy.stanford.edu'. You will be prompted for a password, which we will provide. Once you successfully login, you'll find yourself at the class's Icy home directory: icy:/home/eess141.

connect remotely
In order to use the satellite image processing software, SeaDAS, on ocean.stanford.edu an X Window system is needed, commonly called X11. This will enable you to open new windows from your Unix-session on the PC.
If you have a Mac-laptop running Leopard or newer, then an X11 server is already installed. Just open up a terminal window and log in securely to ocean with X11-forwarding enabled: ssh -X gp235@ocean.stanford.edu. On older versions of OS-X X11 was one of the optional installs. You can find it on the install DVD (click on the Optional Installs icon below 'Install Mac OS X', you might have to scroll down a bit).
On a PC the easiest way is to install Xming and PuTTY. Download Xming from here and a good tuturial to install can be found on the PennState website. PuTTY help on another page.

| top | home | syllabus | lecture notes |