1. Introduction. Basic Concepts of UNIX
The conventions used in this tutorial are as follows:
There are 3 Parts of UNIX, which are:
There are 3 shells that are included in Solaris UNIX, the Bourne, Korn, and C shell. These are only a few of the shells that are available elsewhere (such as Bash, etc.) Each shell has its different functions, and features. The Bourne shell is the most universal and oldest shell available, so it is preferred when writing shell scripts (discussed later).
Primary Shells of UNIX |
|
Shell Name |
Prompt |
Bourne | # |
Korn | $ |
C | % |
There are three components of a command (also called syntax or command formulation). These are:
argument
The command usually follows this structure in UNIX: [command] [option] [argument], so for this example we will use the command ls f /opt. The ls is the command, the f is the option and /opt is the argument. Options almost always have a (dash) in front of them, only a few commands break this rule. In a nutshell, the command is what you want the computer to do, the option is what extra things you want the command to do (or not to do) and the argument is what the command will manipulate. Not all cases require all three of these things, some commands only have a command, some have a command and option, etc. There are two different kinds of commands, simple and complex. A simple command is just one command, while a complex command has two commands, or a complex list with metacharacters. The next topic is metacharacters. A metacharacter is a character that has a special meaning and separates commands.
Metacharacters |
|
Metacharacter |
Purpose |
; (semi-colon) | Separates commands |
> (greater than) | Input |
< (less than) | Uses a file as input |
>> (double greater than) | Appends (puts contents into destination) |
| (pipe) | 1st command as input of 2nd |
* (asterisk) | Replaces more than one character |
? (question mark) | Replaces 1 character |
\ (backward slash) | Separates long commands, using this at the end of a command line and then return will keep it together |
Here is a sample command using metacharacters: To list using *: ls /etc/[a-b] * utilizes a range (will look for files that begin with a or b.)
There is a way for the user or administrator to setup the defaults and system for user preferences, kind of like the autoexec.bat and config.sys files used within DOS. The file is located in:
/etc/profile
.profile for environment variable (global)
.kshrc for alias and set
To make variables transfer to different shells, go into .profile and add the following:
ENV=$home/.kshrc ; export ENV
ENV tells where the environment is
$home/.kshrc tells where the file is
export ENV tells the computer to export that environment to other shells
To have a couple of letters do a specific command use this as an example (this is for the online dictionary): DT=/usr/dict/words Then DT=path
So to display the dictionary words file type more $DT and it will display. To have this shell script transfer to other shells you will use type export DT. To get rid of a variable type unset DT (any variable can be used for the preceding commands, DT is just the example used.) ]
The Shell is the interface between the user and system, basically it translates your words into actions. You can set environment variable with shells home, path (allows searching of executables). To set a path until reboot (temporary) (setting the path tells UNIX where your commands are located, and where to look for any executable you make) do the following for these shells:
C shell Set path = ( /usr/bin usr/ucb ) (do this verbatim with spaces!)
or
Setenv PATH /usr/bin:/usr/ucb
Bourne and Korn Path=/usr/bin:/usr/ucb (to export your paths type export path, this transfers info to other shells)
Some of the standard PATH directorys: (put in this order for speed and so some UCB commands dont come before bin, i.e. the command ls has an entry in System V /usr/bin and UCB /usr/ucb, if you dont have in correct order, the UCB command will be used before bin).
/usr/bin
/usr/dt/bin
/usr/openwin/bin
/usr/ucb (University of California Berkeley)
/usr/local/bin (local programs /usr/sbin (for system admins)
/sbin (for system admins)
$home/bin (your home directory, i.e. /export/home/me)
. (period, this will have UNIX use as a last resort, the directory you are in when you
type an executable)
So the path would be PATH=/usr/bin:/usr/dt/bin: etc and would be put in .cshrc for c shell, .kshrc for Korn, and .profile for Bourne shell.
WHERE THE ENVIRONMENT WOULD BESET UP IN THE FOLLOWING SHELLS |
||
C Shell | Bourne Shell | Korn Shell |
.cshrc (will run in every subshell) | .profile (will run in every subshell) | .profile (will run in every subshell) (env=$home/.kshrc) |
.login (will run in main shell) | .kshrc (will run in main shell) |
To set up a new users initialization file do the following:
C shell for path it could be in .cshrc or .login
Create .login in home directory
Edit and add line set path=(dir:dir:etc) put in the paths where it says dir (i.e. /usr/bin)
Bourne or Korn -
Create .profile
add path=(dir:dir:etc)
To search for a directory use the find command i.e. find / -name ptree print
su (switch user) also to become super user or root can be used two ways: su to just become root or su [username] (i.e. su joe) to become a specific user. When you su you get that users permissions and environment
There are three ways to run a file (ptree will be the example)
[pathname] i.e. /usr/proc/bin/ptree this just runs the command
setenv/PATH=[path] i.e. setenv/PATH=/usr/proc/bin/ptree which will run that executable for that session only
Edit .profile/.login this will keep it forever and is available for the next session
Note: To execute any file you need to have execute permission for all directories (i.e. usr, proc, bin and ptree) before you can run it!
There are many different types of terminals (terminal being a computer hooked up to a server)
telnet
ascii
modem
xterm
Users use terminals to connect to hosts, and UNIX is multi-user, so more than one person can use at a time. Another term used in Unix frequently is Swap -this is when the system writes to the disk to free physical memory (RAM)