Skip to main content

Office of Information Technology (OIT)

UT Arlington
OIT: Office of Information Technology

helpdesk@uta.edu ·  Work Order · 817-272-2208 · System Status

We are your IT partner!

Using UNIX: Advanced Topics Part 1

Description:

Using UNIX


The "Using UNIX Guide"  is available for download to read or print in PDF format.  If you choose to print this document in an ACS lab, print in ranges of 20 pages (print pages 1-20, 21-40, 41-60, etc.) To view this document on the web, follow a link below.


Table of Contents

Conventions

The Basics of Doing Statistics on OMEGA from the Viewpoint of a VM/CMS User
   SAS
   Editors on OMEGA
   Using SAS on OMEGA
Running Programs on UNIX
   Compilers on the UNIX Systems
   Example 1: Sample C Program
   Example 2: Sample C Program
   Example 3: Sample C++ Program
   Example 4: Sample FORTRAN Program
   Example 5: Sample Pascal Program
UNIX Command Chart
  Viewing Files
   Managing Files
   Input/Output Redirection
   Managing Directories
   Multitasking
   Miscellaneous
   Setting Variables

 The Basics of Doing Statistics on OMEGA from the Viewpoint of a VM/CMS User

SAS
Editors on OMEGA
Using SAS on OMEGA

SAS

SAS is a statistical package available on ACS' OMEGA system. The file extension for SAS is .sas,

Editors on OMEGA

OMEGA has an editor called "the" which is a clone of the XEDIT editor on VM/CMS. If you have an
X-Windows terminal, which most of you do not, it works almost identically to XEDIT on VM/CMS. If you are connected to the campus network with a PC running Windows 95, you need to connect to OMEGA choosing a vt220 terminal emulation from the telnet window. This will enable you to use function key f7 to page-up, f8 to page-down, f5 will be the quit key (f3 performs this function on VM), and the insert key will work correctly when using "the". (So far, the keys do not work correctly when using "the" on PCs running operating systems other than Windows 95.) Also, INPUT MODE does not seem to work with any machine setup we have tried. If you have a setup on which the function keys do not work, contact ACS at Ext. 2208 to obtain a copy of the escape sequences which can be used to perform the functions of these keys. Also, if you wish to use "the" you will need to acquire a file called .therc for your account.

Using SAS on OMEGA

If you are logging in to OMEGA from a PC, SAS works much the same on OMEGA as it did on VM/CMS. You create your program with an editor. Save the program in a file with filetype (extension) .sas. Then, at the OMEGA system prompt, type:

% sas filename <return>

Remember to type sas in lower case and yourfilename in the correct case. It should then run and create a file called filename.log which is your saslog and a file called filename.lst which is your listing. The sas commands you used in your programs on VM/CMS should basically be identical to those your will use on OMEGA with the exception that filenames used in FILE, INFILE, and LIBNAME statements will have to conform to UNIX conventions.

Running Programs on UNIX

Compilers on the UNIX Systems
Example 1: Sample C Program
Example 2: Sample C Program
Example 3: Sample C++ Program
Example 4: Sample FORTRAN Program
Example 5: Sample Pascal Program

Compilers on the UNIX Systems

Currently there are two C compilers (DEC C and GNU C), a GNU C++ compiler, and a FORTRAN compiler available on both ACS supported UNIX systems. There is also a Pascal compiler available on OMEGA. The file extension expected by the C compiler is .c. The file extension expected by the C++ compiler is .C, .cc, or .cxx. The file extension expected by the FORTRAN compiler is .f. The file extension expected by the Pascal compiler is .p. Sample programs for each of these compilers are given in this section.

For more information about any of these compilers, please use the man command or the dxbook ( or answerbook) command (for more information on the man command, see "Getting Help"; for information on the dxbook command, see "Accessing UNIX Documentation Using X Windows").

Example 1: Sample C Program

The cc command invokes the DEC C compiler and linkage editor. The gcc command invokes the GNU C compiler. The cc command takes a C source file as input and, if no syntax or linkage errors are found in the C source code, creates an executable image file called a.out. If a file named a.out already exists, it is deleted when the new image file is created.

In the following example, the C program random.c generates ten random numbers with the help of the C rand function.

% cat random.c <return>
#include <stdio.h>
main ()
{
int i, k;

srand(1);
for (k=0; k !=10; k++)
{
i = rand();
printf ("Random number %2d = %d\n", k, i);
}
exit (1);
}
% cc random.c <return>
% a.out <return>
Random number 0 = 1103527590
Random number 1 = 377401575
Random number 2 = 662824084
Random number 3 = 1147902781
Random number 4 = 2035015474
Random number 5 = 368800899
Random number 6 = 1508029952
Random number 7 = 486256185
Random number 8 = 1062517886
Random number 9 = 267834847
%

Example 2: Sample C Program

In the following example, the C program printmain.c prints a line to the screen and then calls an external subroutine sec which is defined in the file printsub.c. The subroutine prints a line to the screen and transfers control back to the calling program which in turn returns control back to the operating system.

% cat printmain.c <return>
#include <stdio.h>

extern void sec();

main()
{

printf ("This is a line in the main C program\n");
sec ();
exit (1);

}

% cat printsub.c <return>
#include <stdio.h>

void sec ()
{

printf("This is a line in the SEC subroutine\n");
return;

}

% cc -c printmain.c <return>
% cc -c printsub.c <return>
% cc printmain.o printsub.o -o print <return>
% print <return>
This is a line in the main C program
This is a line in the SEC subroutine
%

In this example:

The -c option used in the first two cc commands created two object modules called printmain.o and printsub.o.

The cc command was then used to link the two object modules together.

The -o option created an executable image called print rather than a.out.

The following example demonstrates another method of creating the executable image of the files printmain.c and printsub.c:

% cc printmain.c printsub.c <return>
printmain.c:
printsub.c:
% a.out <return>
This is a line in the main C program
This is a line in the SEC subroutine
%

Example 3: Sample C++ Program

In the following example, the C++ program test.cc displays two values contained within the program.

% cat test.cc <return>
#include <iostream.h>
#include <String.h>
#include <stdlib.h>

class myclass {
public:
int a;
myclass (int i) {a = i;};
void showit() { cout << "a = " << a << "\n"; };
};

int main() {
myclass obj1(5), obj2(10);
obj1.showit();
obj2.showit();
exit(0);
}
% g++ test.cc <return>
% a.out <return>
a = 5
a = 10
%

Example 4: Sample FORTRAN Program

In the following example, the FORTRAN program random.f generates ten random numbers with the help of the FORTRAN rand function.

% cat random.f <return>
program randm
integer i, j
do 10 i=1,10
j = irand()
write (6,*) 'Random Number = ', j
10 continue
stop
end

% f77 random.f <return>
% a.out <return>
Random Number = 16838
Random Number = 5758
Random Number = 10113
Random Number = 17515
Random Number = 31051
Random Number = 5627
Random Number = 23010
Random Number = 7419
Random Number = 16212
Random Number = 4086
%

Example 5: Sample Pascal Program

In the following example, the Pascal program random.p generates five numbers from a seed number that the user is prompted to supply.

% cat random.p <return>
program random(input,output);
var RNumber,StartNumber,Counter:integer;
function Random(var Seed:integer):integer;
const
MODULUS=65536;
MULTIPLIER=25173;
INCREMENT=13489;
begin
Seed:=((MULTIPLIER*Seed)+INCREMENT)mod MODULUS;
Random:=Seed;
end;
begin
Counter:=1;
writeln('Enter a seed value.');
readln(StartNumber);
writeln('Here are five random numbers.');
while Counter<=5 do
begin
Rnumber:=Random(StartNumber);
write(Rnumber);
Counter:=Counter+1;
end;
writeln;
end.
% pc random.p <return>
% a.out <return>
Enter a seed value.
8 <return>
Here are five random numbers.
18265 63294 2119 8772 40261

UNIX Command Chart

Viewing Files
Managing Files
Input/Output Redirection
Managing Directories
Multitasking
Miscellaneous
Setting Variables

Viewing Files

cat

Displays file without stopping.

more

Displays file one screen at a time; use <ENTER> to continue or q (quit).

less

Displays file one screen at a time; use b (back), f (forward), and q (quit).

head -n

Displays firstn number lines of file (default 10).

wc

Displays the number of lines, words, and characters in a file.

cmp

Compares then reports the differences in two files.

diff

Compares then reports the differences in two files and the ex editor commands that will make them identical.

grep xx

Searches for a regular expression xx in a file.

sort

Alphabetically sorts the lines in a file.

lpr

Prints a file.

tail -n

Displays lastn number of lines of file (default 10).

Managing Files

ls

Displays contents of a directory.

rm

Removes (deletes) a file from a directory.

cp

Copies a file.

mv

Moves (renames) a file.

wc

Displays the number of lines, words, and characters in a file.

chmod

Changes the protection assigned to a file.

ls -l

Displays protection assigned to each file.

Input/Output Redirection

> 

Redirect standard output.

>> 

Redirect and append standard output.

>&

Redirect standard output and standard error.

>>&

Redirect and append standard output and standard error.

< 

Redirect standard input.

<<xxx

Redirect standard input up to a line identical with xxx.

|

Redirect standard output to another command.

Managing Directories

pwd

Prints (displays) the current working directory.

cd

Changes the current working directory.

mkdir

Makes a new directory.

rmdir

Removes a directory.

Multitasking

nice x &

Runs command x as a background job.

jobs

Displays the status of any background jobs.

fg

Returns a background job to the foreground.

stop

Stops a currently running background job.

kill

Cancels a currently running background job.

Miscellaneous

history

Displays the last 20 (by default) commands used.

!!

Executes the last command used.

!n

Executes the command numbered n on the history list (displayed by history).

!xxx

Executes the most recent command starting with xxx.

!-n

Executes command used n commands ago.

alias

Creates a nickname for a command.

cal

Displays a calendar for the current month. If specifying year, specify all four digits.

date

Displays the current date and time.

who

Displays all users who are logged into the system.

Setting Variables

set

Displays current shell variables and their values. Also sets new value for specified variable.

echo $x

Displays current value for variable x.

printenv

Displays current environment variables and values.

setenv

Sets current value for environment variable.

who

Displays all users who are logged into the system.

To see all options and arguments available with each command, type man (on OMEGA) or answerbook (on GAMMA) followed by that command's name.

For an online help screen, type help.






Available To:

  • Vendors
  • Students Admitted to UT Arlington
  • Visitors and Guests
  • Faculty (currently appointed) and Staff
  • Departments and Offices at UT Arlington
  • Retirees
  • Event-Based

System requirements: None, Solaris, Linux