Introduction to UNIX Computing at SHSU
Introduction
This document is intended for general users of systems using the UNIX operating system, and its objective is to introduce basic UNIX concepts and commands to the reader. The % and $ symbols represent commands or shell prompts, and arguments inside of brackets indicate that something needs to be typed (without the brackets). For example [name] would imply that you need to type your name in that space, and [return] indicates that you should press the Return key. Text in monospace font is what is actualy displayed on the screen.



UNIX Overview
UNIX is an operating system that:


UNIX System Components
The kernel is a program that manages the resources of a UNIX system. It keeps track of peripheral devices (printers, terminals, etc.), schedules jobs, and provides a file system that manages long-term storage of data files. Basically, it is the operating system.

The shell is a command interpreter that acts as an interface between the user and the operating system. It is not part of the operating system, but it translates your requests into actions for the kernel; it is a program that runs under UNIX.



Directories
Directories are useful for organizing files in a structured manner, much like folders containing documents in a file cabinet. To make a directory type mkdir [dirname]. Subdirectories can be made in the directory using the same command. Type cd [dirname] to change your present working directory to [dirname]. To create a subdirectory, type mkdir [subdirname].

UNIX has a hierarchical directory structure that is comparable to an upside-down tree, with the root directory at the top,symbolized by the slash (/). Directories can be considered the branches of the tree, while files can be thought of as the leaves.



Path Names
In UNIX it is possible to have the same filenames for files in different locations on the system. For this reason, you can specify filenames by including directory names of where the file "lives"; this type of filename is called a pathname, and each directory is separated by a slash (/). For example, the file program1 might exist on two directories but contain different information:
/home/sue/class/program1
/home/sam/cis290/programs/program1
These filenames are called absolute (or full) pathnames because they can be traced from root and begin with a slash. Sometimes it is more convenient to specify a pathname relative to your present working directory. This type of pathname is called a relative pathname and does not begin with a slash. For example, when Sue is in her home directory (/home/sue), the relative pathname of the file program1 is class/program1.
  • A dot (.) represents the current directory (the directory you are presently in). When Sam is in his cis290 directory, the programs directory can be referred to as /programs. Two dots (..) refer to the next directory level up, or the parent directory. If Sue is in /home/sue, and she wishes to move to /home, she may enter the command cd ..



  • Logging In To UNIX
    The university provides unx1.shsu.edu as a generally accessible UNIX system for faculty and students at Sam Houston State. The general way to login to a UNIX computer (Note: UNIX is case-sensitive and uses mostly lowercase. Do not login in uppercase!):
     
  • Remote login from an inter-networked computer (e.g., a workstation, a VAX):

  • telnet [machine_name] [return] (where machine_name is the hostname of the remote system) or rlogin [machine_name] [return] (see console login: prompt below)
     
  • From the console: login: [userid] [return] (where userid is your login name, i.e., abc1234) Password: [your_password] [return]



  • Listing Files
    To see the files in the current directory use the ls command: For Sam to get a list of the files in his cis290 directory while in his home directory, he could type: Sue can get a long listing of all files in her current directory using the option -l: The first line, total 32, gives the total amount of disk usage in blocks. The rest of the output gives information about each file in the directory. The first character on the line tells you what type of file it is: a - is a normal file and a d means that it is a directory. The remainder of the first of seven fields relates to file permissions information.

    Files that begin with a dot are called hidden files because they are not normally shown when using ls. Some common hidden files are: .profile, which is read upon login when using the Bourne or Korn shells; .login and .cshrc, both interpreted by the C shell upon login; and .bash_profile and .bashrc are bash startup files. Use ls -a to list all your files:

    The current directory, ., and the parent directory, .., are also shown.



    Viewing Files
    The simplest way to view a file is to use the cat command:
    % cat [file_name] [return]
    Using the cat command is quite convenient if file_name is a short file.
    If you have a longer file to view use the more or pg commands, which work similarly in that they both display one screen of text at a time:
    % more [file_name] [return]
    For both more and pg, a q will quit paging and return to the command prompt.



    Moving and Renaming Files
    Moving and renaming files is done with the mv command. For instance, Sam could move the file program1 from his home directory to his cis290 directory, where it will keep the same filename:
    % mv program1 cis290 [return]
    As another example, Sue could rename pgm.c to old_pgm.c:
    % mv pgm.c old_pgm.c [return]
    Note that mv actually removes the original file and moves it.



    Copying Files
    The command for copying a file, cp, is similar to using the mv command. Sam could make a copy of the file program1 and call it project1:
    % cp program1 project1 [return]
    To copy pgm.c, currently in her home directory, to her programs directory and call it the same thing, Sue would issue the following command:
    % cp pgm.c programs [return]
    This would create a file called /home/sue/programs/pgm.c.



    Removing Files
    To remove a file on UNIX use the rm command. For example, if Sue wanted to remove the file pgm.c from her home directory she would use the rm command:
    % rm pgm.c [return]
    In UNIX, the only way restore a file is from a tape or disk backup, so many users prefer to use the interactive option, -i, when using the rm command; only by responding with a y will it delete the file:
    % rm -i pgm.c [return]
    pgm.c: y [return]


    Other Basic UNIX Commands
    In addition to the commands mentioned above, here are some other UNIX commands that you may find useful:

    On-Line Manual
    Any additional information that you may need on UNIX commands can be found in the on-line UNIX Reference Manual. Type:
    % man [command] [return]
    where [command] is the command in which you are interested. The command man ls, for example, will show you the portion of the manual that deals with the command ls. Also, man -k keyword on most UNIX systems enables you to find the man page(s) that have keyword in their titles, such as man -k perl.


    Modified September 10, 2000