An Introduction to Stats UNIX Cmds
at William and Mary
(By Bob Dawson, Academic User Support)

Table of Contents

Introduction
1. UNIX Cmd Format
2. Filenames
3. Specifying Multiple Files
4. File Protection Against Accidental Removal
5. UNIX Directory System
6. Backgrounding/Foregrounding/Suspending a UNIX Job
7. How to Continue Running a Job after Exiting Stats
8. Getting Help on UNIX
9. Printing Stats UNIX Files
10. Logging Out of Your UNIX Login Session
11. Suggested Reference to Get Started with UNIX

Introduction (GoBack)

The UNIX system for statistics/math  applications at William and Mary is named Stats  and uses the KORN shell type UNIX; it is a Solaris 9.0 system. Stats like any UNIX computer is case sensitive; all cmds are used in lower case, while filenames can be lower, upper, or mixed. For example, to display file "myprog.lst" in pages prompted by "MORE", you enter this cmd: more myprog.lst If the file is "MYPROG.lst", you type  more MYPROG.lst (use ENTER key to scroll one line, SPACE bar to scroll one screen with the "more" program.)

The exception to UNIX case sensitivity is the use of "Ctrl" cmds. To both illustrate this and give you some important "Ctrl" cmds, consider these: "Ctrl-c" or "Ctrl-C" cancels a job in the foreground (see Section 6 Foreground discussion below); "Ctrl-z" or "Ctrl-Z" suspends a foreground job; and "Ctrl-d" or "Ctrl-D" logs you out when at the "$" UNIX prompt.

Other "Ctrl" cmds of note are "Ctrl-s" or "Ctrl-s" to freeze your terminal display (may be necessary when not displaying with "MORE" paging) and "Ctrl-q" or "Ctrl-Q" to unfreeze.

1. UNIX Cmd Format (GoBack)

Many UNIX cmds have this format:  cmd-name [options] cmd-specs where "[]"s are not typed and represent basic option specifications identified by a "-" prefix. The "cmd-specs" is sometimes optional too. Consider as an example, the "ls" cmd to list file information; you simply type  ls to display just the names of all files in the current directory. To display only ".lst" filenames, you enter  ls *.lst To get all information about your ".lst" files, you key  ls -l *.lst where the option "l" (meaning long format) is specified to get the extra information; this cmd illustrates how basic options are flagged with a "-" character. If you add the "-F" flag you get even more information: file names are trailed with "/"s, "*"s, "@"s, etc.; these respectively identify directory files, executable files,  link files, etc.; the "-F" flag is highly recommended,  especially if you use "ls" with no file name-specs as in the following illustration of the "-F" flag:
ls -lF
Even more  information can be obtained with the "-a" all file flag exemplified as follows:
 
ls -lFa

which now include hidden files in the list; hidden files are prefixed with a "." such as the ".profile" file which you can optionally use to over ride/supplement your default profile. See example use of ".profile" in Section 4 below, where it talks about using it to automatically execute the "alias" command upon login. Your default profile can be seen via this "cat" cmd:

cat /etc./profile

The "cat" cmd generally has this format

cat filename

and simply displays the contents of file "filename" (we discuss "filename" next)

2. Filenames (GoBack)

UNIX filenames are unlike DOS PC files in that they can be virtually any length and as mention above are case sensitive (the latter illustrated by the UNIX filenames"myprog.lst", "MYPROG.lst", and "MYPROG.LST" being totally different files).

UNIX files have no system recognized "extensions" or "file types" to further identify them; for the current directory, files are recognized by filenames alone.  Note,  however, that software on UNIX may  recognize and require these identifying elements (e.g., on Stats Fortran source files must have the extension "f" or "for" before Fortran will compile them).

UNIX filenames are probably best kept to alphanumeric characters and periods ("."), since several special characters are interpreted by UNIX for other purposes. You can use any number of "."s; for example, "my.prog.in.f" is just as valid as "myprog.f"; however, filenames with leading "."s are hidden (e.g., ".profile") and, as mentioned in 1. above do not list with the "ls" command unless you include the "-a" option (e.g., "ls  -la" to long list all files and  better yet,  recommended, "l -lFa" to also include the file identifiers:  trailing "/"s, "*"s, @"s, etc. to mark respectively directory files, executable files,  link files, etc.).

3. Specifying Multiple Files (GoBack)

As with PC DOS files, you can specify multiple files in UNIX via wild card symbols; e.g., "*.lst" defines all UNIX files that end in ".lst" (as illustrated with the "ls *.lst" command in 1. above for listing all ".lst" files). The will card  "??.lst" specifies only UNIX files that start with two characters followed by ".lst". UNIX, however, goes beyond the wild card specs by permitting "regular expressions" to define files; "regular expressions" include both wild cards and an array of other symbols to specify a file set; it lets you, for example, name all files ending with a "1 through 5" digit when you type "*[1-5]"; in another "regular expression" example keying "my*[1-5].lst" references all files that begin with "my", end with ".lst",  and have a digit in the "1 through 5" range just before the ".lst". For a complete run down on "regular expressions", see UNIX in a Nutshell (ref 12.b below).

4. File Protection Against Accidental Removal (GoBack)

Files not write protected are removed "no questions asked, no remarks" with this cmd:  rm file-spec where "file-spec" can be a filename or a "regular expression" such as "str.*" or "str[1-5].*", etc. ( "str" being alphanumeric). Thus,  rm *.lst removes all files ending in ".lst", nothing said. If you instead enter  rm -i *.lst the "-i" interaction flag causes UNIX to ask permission to delete each "*.lst" file, one at a time. You can write protect your "*.lst" files but we don't recommend it so we don't show you how; instead we recommend that you include this "alias" cmd in your ".profile" file: alias "r=rm -i"

This "alias" command will automatically execute when you log into Stats so that you have the alternate "r" cmd to remove files; when you use "r" to remove files, Stats automatically asks permission to delete the specified files; thus, instead of you using "rm -i" to remove files with permission, just "r" does it more conveniently; for example, this "r" cmd:

r *.lst

asks permission to delete each "*.lst" file, one at a time. For more about the ".profile" file, see the latter part of Section 1 above where it discusses the "ls -lFa" cmd.

The "ls -l" cmd displays a file's protection status at the beginning of the line that describes the file (a "w" as the 3rd char in the line means write privileges; else the file is write protected from the user); however, because "H:" files at W & M share with files on Stats, the default permission codes for new files do not show correctly on Stats. On Stats the permission codes show as "rwxrwxrwx" for a new file,   permission for both owner and other users to do anything with the files (full access); this is not true. So please ignore this information.

Note: because you can easily remove a lot of files with the "rm" command without even knowing it -- for example the cmd "rm *" can removes most files from your current directory, nothing said -- we request that you be careful with the "rm" cmd (again recommend including this cmd: alias "r=rm -1" in your ".profile" file so that the "r" cmd does it asking for permission with each file). If you need to restore removed files, you can request restored them with backup copies via E-mailing to this address:

support.wm.edu

Final Note: you can directly protect files from accidental deletion by preceding their names with a ".", classifying them as hidden; that way even "rm *" will not remove them ("rm .*" will, but here you tell it to remove all hidden files and should be aware of it).

5. UNIX Directory System (GoBack)

UNIX directories are defined and referenced similar to PC directories; however, when you access the PC's command line either by clicking Command Prompt in the Programs menu or Run in the Start menu, there is, one difference the backslash "\" delimiter of the PC  has its direction reversed on UNIX, becoming instead a forward "/" slash.  To learn the directory for your account disk area on Stats, enter  SET and observe the setting of the "HOME" system variable. The "HOME" directory is automatically the current directory when you login; on Stats it is "/home/your-user-id" where "your-user-id" is your log in user id (notice again that the delimiter slashes here are forward type, not backwards as on the PC).

To create a sub directory of "HOME" (on Stats a sub directory of specifically "/home/your-user-id"), you type this when "HOME" is the current directory:

 mkdir new-dir where "new-dir" is the name of your new sub directory. For example, to make sub directory "mysubdir", you enter  mkdir mysubdir To make "mysubdir" the current directory, key  cd mysubdir To make "HOME" the current directory (again automatically when you 1st login), you can enter any one of the following:  "cd $HOME", "cd ~/", or just plain "cd" Or of course, more conventionally, more directly,  you can use this to make "HOME" current:
cd /home/your-user-id
To remove a directory, for example, "mysubdir", you do this:

rmdir mysubdir

This will remove "rmdir" if and only if you have removed all files and subdirectories from "mysubdir".

 

6. Running a UNIX Job: in Foreground/ Background/ Suspension (GoBack)

When you execute a cmd at the Stats cmd line, you create a foreground job; for example, if you execute "ls", you run a foreground job to list files in your current directory. Or to run, for example, your Fortran or C program (compiled and stored in file "myprog.out") in the foreground, you execute this:

./myprog.out

at the Stats cmd line. Note that the "./" tells Stats to specifically run file "myprog.out" located in the current directory; otherwise Stats will not know where to find the file, as it normally just looks in the Stats system directories (which is why a standard UNIX cmd like "ls" requires no directory spec because "ls" is a system cmd). Here the "myprog.out" job remains a job until completion or you either cancel it with "Ctrl-c" or suspend it with "Ctrl-z"; if the latter you can resume with the "fg" foreground cmd, run it in the background with the "bg" background cmd (further discussed below), or you can kill it with the "Kill" cmd.

To run "myprog.out" in the background to begin with (so you can do other things at the Stats cmd line), you can use the "bg" foreground cmd (or alternately leave out "bg" and just end the all with an "&", the more popular way) as follows:

bg ./myprog.out

or ./myprog.out &

This works Ok if "myprog.out" does no interactive I/O; that is, all I/O comes from/goes to files(s).. Assuming, however, that "myprog.out" does all I/O interactively at the Stats cmd line (receives input from the cmd line, display output starting at the cmd line). you need to redirect the I/O as follows when you background the job::

bg ./myprog.out < myprog.dat > myprog.lst

or alternately this:

./myprog.out < myprog.dat > myprog.lst &

where "<" says accept the input from file "myprog.dat" (instead of at the cmd line) and ">" directs the output to file "myprog.lst" instead of to the monitor.

You can display the status of any job (foreground. background, or suspended) by keying  jobs (or alternately typing "ps -l" to display more job information such as time; note other processes/jobs list; just ignore).

You can kill any suspended or background job by entering

 kill %n where "n" is the list number in "[]"s that displays when you execute the "jobs" cmd.

You can also run  an X-Windows application in the background, allowing you to access the Stats cmd line to do other things (such as file management), while returning you any time to the X-Windows application, still in the background; consider this detail example:  if you run X-Windows SAS with this cmd:

sas&

you open the X-Windows SAS Display Manager as a background job; since the Stats's cmd line remains open when only background jobs run, you can now,  for example,  list your files, possibly even display some searching for the SAS program file to process;  having found the file, you  return to the SAS Display Manager by clicking on the appropriate SAS sub window or sub window icon on the Task Bar ( the one for the SAS Editor),  access the file (open the SAS program file in the Editor), and process it. Of course if you run X-Windows SAS before you know you need to check your files for the SAS program,  you can type "Ctrl-z" to suspend,  "bg" to background SAS,  check out your files at the Stats cmd line, return to SAS, now running in the background,etc.

You can also process a SAS program independent of the SAS Display Manager and also Stats being in X-Windows mode (necessary to access the SAS Display Manager); for example to do this with statements in text file myprog.sas, execute this at the Stats cmd line:

sas myprog.sas

and as with the example Fortran program above, if you want to do this in the background so you can do other things at the same time, you add on the background operator "&" as follows:

sas myprog.sas &

7. How to Continue Running a Job after Exiting Stats GoBack)

There maybe times that you prefer logging out of Stats while one of your job continues to run; for example, if it is a number crunch er and may take a long time; you can do this by running it with the "no hang up" command using this format:

nohup "command-to-run-the job" &

where "command ..." is is what you normally type to create/run the job and "&" runs it in the background; as mentioned above the latter lets you get back to the Stats command line to exit or if you wish, do other things, and exit later. For example this job using "nohup":

nohup sas myprog.sas &

runs the SAS statements in text file "myprog.sas" (assume they take a very long time to process); because of the optional "&" this job runs in the background so that when you log out of Stats the statement processing continues. Specifically what you do after running "nohup" as above is press the Enter key to return to the Stats command line; then anytime afterwards you can log out (exit) if you wish with again the "SAS program' job continuing its execution. When you log back into Stats, you can check the status of this job by executing this "ps" process command (a process being being jobs that Stats runs to support your log in plus those you start including your "nohup" job):

ps -ef|grep your-id

where "|" is the vertical bar character known as the pipe command in Stats and "your-id" is your Stats id (also your W & M id); "ps ef" by itself lists all current processes for all users Stats for all users; by including the "|" command, you pipe all listed processes to the "grep your-id" command which retains only those listed with "your id" and thus lists only your processes (again including any of your "nohup" jobs). In our SAS program example, the process associated with the above "nohup" command has "sas myprog.sas" trailing its listing; this identifies the "nohup" program (job) as still executing; it also gives its "process id" as the second number in the list; you can use the "process id" to kill the process (job) with this command:

kill "nohup process id"

Of course if your "nohup" doesn't list to begin with, then your program has finished execution.

8. Getting Help on UNIX (GoBack) On Stats you can help via the "man" (manual) command. For help with a specific Stats  command, you enter

 man cmd-name where "cmd-name" is a UNIX cmd; e.g., to learn the structure of the list file(s) command "ls", you type:
man ls
For help via key words, you enter
man -k keyword
Thus, this "man" command:
man -k files
lists/describes commands for doing file work; from here you can get more help with a listed command via the "man cmd-name" format.
 

9. Printing Stats Files  (GoBack)

Normally, you would use the "lpr" cmd ("line print" cmd) to print files from a UNIX computer like Stats, but currently Stats in not connected  to a printer at William and Mary. However there are ways to print Stats's files on your PC's local printer. Because your Stats SSH window will print its display to your the local PC printer, you can readily print a text type file (limited to approximately 8 pages) by displaying it and then printing it; you can display it with the "cat" Stats cmd exemplified as follows:

     cat myprog.lst

which displays file "myprog.lst"  (again assumed here to be text type and <= 8 pages); then you select what you wish to print, click your Stats File menu item, then Print, etc.

If your printout exceeds the approximated 8 page limit, you can bring up the text UNIX file in almost any  PC's Editor (NotePad being the exception)  and print from there. You can readily do this if your PC is mapped to the "H:" drive at W & M (automatically done in the W & M labs at log in time); if this is your own PC and you are connected to the W & M campus network (which it should be if in a W & M office/resident hall), you should be able to map to "H:" via the following:

Open Windows Explorer, then Tools, then Map Network Drive, and in the emerging window, do the following:
Select "H:" from the Drive pull down
Enter the following in the Folder text box:
\\netstore\your-user-id$
and press ENTER
If this works, you should see "H:" listed in your Windows Explorer left sub window.

If you can not map to "H:", you can print a Stats's text file still another way on your PC. If you SFTP to Stats (PACLab Tips, Appendix D, for how in the labs), you get a list of your Stats's home directory (folder) files; then  all you have to do is find the file to print in this list (either at the root of your home dir or within a sub directory); then click the file name, and drag and drop to your PC hard drive; from there print to your local PC printer (e.g., by opening the file in Microsoft Word and printing it. This is of course desirable if you want to print more copies latter as a copy is now on your own PC.

If your Stats output file is binary (an image file supporting graphics work, for example) and you have "H:" access, all you have to do is bring it up in any PC graphics editor and print from there; if "H:" is not accessible, you take the SFTP route mentioned above.  and bring up the image file from your hard drive, etc.

10. Logging Out of Your UNIX Login Session (GoBack)

Key "logout", "exit", or "ctrl-d" to log out of UNIX.

11. Suggested Reference to Get Started with UNIX (GoBack)