UNIX Seminar - Rahman Tashakkori Department of Physics, Southern University and A&M College

This manual is designed to familiarizes users with some of the commonly used UNIX commands. Please follow all the instructions. The first thing we need to do is to work on a machine that has UNIX as its operating systems. If you are already on a UNIX machine skip step (0) otherwise go to step (1).

Step (0) : Getting into a UNIX machine from a PC : User is using a PC with Windows operating system to connect to a UNIX machine through Telnet. To establish the connection use the Telnet manual first and after you connected to the UNIX machine go to the next step.

Step (1) : Logging into the machine: We need a Login Id and a Password. These two are unique to each individual. For the purpose of this seminar only, we have created an temporary account use :

Login : students (Enter) Password : temp98 (Enter)

You will get the command prompt : grant%

1-0) To Check who you are (just in case you are not sure) type : whoami

1-1) To find information about someone, for instance Rahman Tashakkori, who may have an account on this system type :

finger rahman OR finger Tashakkori

1-2) To check the date type : date

1-3) To create a directory on the system type : mkdir (any name)

1-4) To get a listing of the contents of the directory that you are in type : ls

1-5) To go to that directory type : cd name of the directory (from 1-3)

1-6) To check where you are in the system type : pwd (what directory)

1-7) To create two directories under the newly created directory :

type : mkdir dir1

mkdir dir2

1-8) To go to dir1 type : cd dir1

1-9) To go back one step down type : cd ..

1-10) To go to dir2 type : cd dir2

1-11) To go back all the way to the home directory (/home/class/students) type : cd

1-12) Go to the directory you created in step 1-4 (cd name of the directory). Type

pwd to make sure you are in your own directory.

1-13) To copy three files (file1, file2, file3) from the home directory type:

cp /home/class/students/file1 . OR cp /home/class/students/file1 file1

cp ../file2 . OR cp ./file2 file2

cp /home/class/students/file3 /home/class/students/yourdirectory/file3

type ls (you should see all three files)

1-14) To rename file1 to history type : mv file1 history (type ls, any change ?)

1-15) To make a copy of file history type : cp history history-org

1-16) To see the contents of the file history type : more history

1-17) To delete file3 type : rm file3

1-18) To delete directory dir2 type : rmdir dir2 (type ls to list the contents )

1-19) To see the contents of a directory with all details type : ls -la

1-20) To copy file test.c from the instructor directory type : cp ~phy200z/test.c .

1-21) To copy file test2.c from the same directory type : cp ~phy200z/test2.c .

1-22) To copy file input form the instructor directory type : cp ~phy200z/input .

1-23) Type ls to see the list the contents of the directory

Step (2) : Compiling and Running a C program

This test.c file is a simple program written in C. Letís see if we can compile and run it. Notice that the C files has ".c" extension.

2-1) To compile the test.c type : cc test.c (creates an executable file as a.out)

2-2) To run the code type : a.out

Letís try to run a program the reads and input and put the output in a file using directives.

2-3) To compile the test2.c program type : cc test2.c

2-4) To run the program with input/output type: a.out < input > output

the input file already exists and after you run the program the output file will be created.

2-5) To see the contents of the output file type : more output

2-6) To print the file type : lp output

Step (3) : Script (save all the actions in a file).

Usually you want to have a file that includes your program, your input, and your output. In other words, a file that contains all the activities you had to get your program to the end point and more importantly includes the time stamp. Script is a powerful tool provided by UNIX for this purpose.

3-1) To start the script type : script

** you can choose a name for your script too, this way you type : script name

3-2) To view your program in the script type : more test2.c

3-3) To compile the program type : cc test2.c

3-4) To run the program type : a.out < input > output

3-5) To view the output file type : more output

3-6) To stop the script press Cntrl and D at the same time.

You have created the file typescript that contains all the actions from 3-2 to3-6.

3-7) Type ls to make sure that script file (typescript) exists

3-8) To mail the file to the instructor type : mail phy200z < typescript

rev : Aug. 24, 1998