264 lines
13 KiB
Plaintext
264 lines
13 KiB
Plaintext
![]() |
H-NET H-NET H-NET H-NET H-NET H-NET H-NET H
|
|||
|
N N
|
|||
|
E ** H-Net Magazine ** E
|
|||
|
T T
|
|||
|
H Volume One, Issue 1, File #03 of 20 H
|
|||
|
N N
|
|||
|
E An Introduction to UNIX, by MINOTAUR. E
|
|||
|
T T
|
|||
|
H-NET H-NET H-NET H-NET H-NET H-NET H-NET H
|
|||
|
|
|||
|
|
|||
|
UNIX is widely-touted as 'the operating sustem of the future', though in fact
|
|||
|
it dates from 1969 (it was developed originally by Bell Laboratories, which
|
|||
|
runs most of the telephone systems in the USA). Since then it's been under
|
|||
|
continuous development; so it's not so much an old operating system as a fairly
|
|||
|
mature one, if you see what I mean. Hackernet BBS has many unix files for you.
|
|||
|
|
|||
|
Unix gets brownie points straight off because it was conceived by a user of
|
|||
|
computers rather than a software specialist or some other sort of software
|
|||
|
designer. So it is relatively easy to use; which nearly all other software the
|
|||
|
prime goal often seems to be to make money, or to sell more hardware and
|
|||
|
software, or whatever.
|
|||
|
|
|||
|
In brief, UNIX is a general-purpose, multi-user operarting system with a clever
|
|||
|
method of holding files. It's a complex system, which means both that it is
|
|||
|
rich in facilities and difficult to get to grip with - until now!.....
|
|||
|
|
|||
|
BEGINNER'S GUIDE TO THE WONDERFUL WORLD OF UNIX
|
|||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|||
|
|
|||
|
The aim of this first textfile is to give an insight into the fundamentals of
|
|||
|
UNIX. Subsequent textfiles will delve into all areas of UNIX in greater depth.
|
|||
|
|
|||
|
WHAT IS UNIX?
|
|||
|
~~~~~~~~~~~~~
|
|||
|
|
|||
|
The UNIX operating system can be divided into a number of distinct parts. First
|
|||
|
there is the part of the system which performs all of the interface to the
|
|||
|
hardware, scheduling disks, managing memory, handling terminal I/O and
|
|||
|
generallu handling any requests to and from the devices on the system. This
|
|||
|
part of UNIX is called the UNIX Kernel. It is in fact one large, compiled 'C'
|
|||
|
program which is kept on the hard disk and loaded into memory when the system
|
|||
|
is booted up. The UNIX Kernel is always kept in memory because practically
|
|||
|
everything that is done on UNIX uses the Kernel. Buts on its own, it is of
|
|||
|
little use. There is no point in just having an interface to the hardware - an
|
|||
|
itnerface to the user is also required. This is provided by the UNIX shell.
|
|||
|
|
|||
|
The shell is another name for a TIP (Terminal Interface Program) or a JCL (Job
|
|||
|
Control Language). Its job is to read input from the terminal and execute the
|
|||
|
right programs, depending on the input. A program which is executing in UNIX
|
|||
|
is called a process. In fact, the shell is also a 'C' program which is
|
|||
|
executing for each terminal which is logged on. It reads input from the
|
|||
|
terminal, interprets the input in various ways and starts the appropriate
|
|||
|
processes.
|
|||
|
|
|||
|
As well as interpreting input and executing processes, the shell has its own
|
|||
|
control-flow constructs and it can therefore be used as a programming language.
|
|||
|
It also handles pipes and redirection of I/O which will be the subject of a
|
|||
|
later textfile.
|
|||
|
|
|||
|
The way the UNIX shell works is much the same as other operating systems. It
|
|||
|
displays a prompt, normally '$' the user types in the command to execute and
|
|||
|
the shell reads the command, searches for the program which is the same name as
|
|||
|
the command typed in and it then executes this file, if it found it. When the
|
|||
|
program finishes executing, the shell redisplays the prompt to the terminal.
|
|||
|
|
|||
|
OK, so we have a Kernel to handle the devices and a Shell to interpret input
|
|||
|
form the users terminal. The final and by far the largest part of UNIX is the
|
|||
|
Programs. There are many Programs in UNIX which form a part of the operating
|
|||
|
system. In UNIX jargon, these are called Utilities.
|
|||
|
|
|||
|
There are Utilities to look at directories, edit files, semd files to the line
|
|||
|
printer, perform backups, look at files, delete files, the list is endless.
|
|||
|
These Utilities are, to the user, commands which are typed in at the terminal
|
|||
|
prompt. For example; 'ls' is the UNIX Utility to list the directory; 'cd' is
|
|||
|
the Utility to change directory. In some systems the Utilities form a part of
|
|||
|
the terminal interface program which interacts with the user. In UNIX, very
|
|||
|
few Utilities are a part of the Shell, the majority of them are external to the
|
|||
|
Shell and are called up whenever they are needed.
|
|||
|
|
|||
|
This is because there are 200-300 UNIX Utilities, and including all of them in
|
|||
|
the shell would obviously increase the size of the Shell to an unreasonable
|
|||
|
level. It is much neater to keep them on the disk to be called as and when
|
|||
|
they are needed.
|
|||
|
|
|||
|
On a typical UNIX system, as well as the operating system, there would also be
|
|||
|
some other packages, word processing, spreadsheets, etc. These are necessary
|
|||
|
because UNIX does not include any of these - UNIX is only an Operating System.
|
|||
|
|
|||
|
|
|||
|
THE UNIX FILE STRUCTURE
|
|||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|||
|
|
|||
|
The above description of UNIX is very conceptual. You never actually se the
|
|||
|
UNIX Kernel, excpept perhaps as a process on the system. The Shell too, is
|
|||
|
just always there when you login. The file structure, however, has to be
|
|||
|
manipulated and managed by the user all the time. The UNIX file structure is
|
|||
|
hierarchical.
|
|||
|
|
|||
|
Within the file structure there are files and there are directories - as shown
|
|||
|
in the diagram below :-
|
|||
|
|
|||
|
/(root)
|
|||
|
|
|||
|
|
|
|||
|
_________________________________________________
|
|||
|
| | | | | | |
|
|||
|
bin dev etc lib tmp unix usr
|
|||
|
| | | | | | |
|
|||
|
----- ----- ----- ----- ----- ----- -----
|
|||
|
| | | | | | | | | | | | | | | | | | | | |
|
|||
|
--- ---
|
|||
|
||| |||
|
|||
|
|
|||
|
Files contain data and directories contain either files and/or directories. At
|
|||
|
the top of the hierarchy is the ROOT directory, this is sometimes referred to
|
|||
|
as /(slash). Below the root directory are the system files and directories.
|
|||
|
|
|||
|
When a user logs into the system, he logs into his HOME directory. Every user
|
|||
|
of the system has a HOME directory where he can create and delete files and
|
|||
|
directories. This part of the system belongs to him. User directories are
|
|||
|
usually kept in the directory 'usr' which is directly below the root directory.
|
|||
|
For example, say the user Fred has the directory structure as shown below :-
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/(root)
|
|||
|
|
|
|||
|
usr
|
|||
|
|
|
|||
|
fred
|
|||
|
|
|
|||
|
----------------------------------
|
|||
|
| | | | |
|
|||
|
cprogs memos wpfles sprdsht pending
|
|||
|
| | | | |
|
|||
|
----- ----- ----- ----- -----
|
|||
|
| | | | | | | | | | | | | | |
|
|||
|
1990
|
|||
|
|
|||
|
When Fred logs on he will automatically go to the directory 'fred'. If
|
|||
|
however, Fred wants to examine his spreadsheets, he may want to go to the
|
|||
|
spreadsheet directory. He would do this by using the 'cd' command to change
|
|||
|
directory, i.e:
|
|||
|
|
|||
|
$cd sprdsht
|
|||
|
|
|||
|
This command would make his CURRENT DIRECTORY the spreadsheets directory but
|
|||
|
his HOME directory wouls remain the same. If he wanted to move to his 1988
|
|||
|
directory from his home directory the command would be :
|
|||
|
|
|||
|
$cd sprdsht/1990
|
|||
|
|
|||
|
The '/' between the two directory names is the delimiter.
|
|||
|
|
|||
|
The construct 'sprdsht/1990' is called a Pathname. Infact this particular type
|
|||
|
of Pathname is called a Relative Pathname because it is relative to the
|
|||
|
directory the user is currently in. That is, the path 'sprdsht/1990' would be
|
|||
|
meaningless if the users current directory was 'wpfls'.
|
|||
|
|
|||
|
Another type of pathname is an Absolute Pathname. This, as the name suggests,
|
|||
|
is a path from the root directory and is therefore independent of the user's
|
|||
|
current directory. Absolute pathnames are represented by using a '/' as the
|
|||
|
first character of a path. For example, the Absolute Pathname of the directory
|
|||
|
mentioned would be '/usr/fred/sprdsht/1990'.
|
|||
|
|
|||
|
The command :-
|
|||
|
|
|||
|
$cd /usr/fred/sprdsht/1990
|
|||
|
|
|||
|
would take Fred right to the directory regardless of his current directory. the
|
|||
|
command to find the Absolute Directory is :-
|
|||
|
|
|||
|
$pwd
|
|||
|
|
|||
|
The stands for 'print working directory'. As mentioned above, the command to
|
|||
|
look at the contents of a directory is 'ls'. By simply typing :-
|
|||
|
|
|||
|
$ls
|
|||
|
|
|||
|
a list of filenames is output. This looks like :-
|
|||
|
|
|||
|
cprogs
|
|||
|
memos
|
|||
|
wpfls
|
|||
|
sprdsht
|
|||
|
pending
|
|||
|
|
|||
|
This is fine if just the names is required but, it is impossible to tell from
|
|||
|
this information which are files and which are directories. As with a lot of
|
|||
|
UNIX commands, the 'ls' command performs a mimimum function.
|
|||
|
|
|||
|
UNIX commands, generally speaking, have a number of options which can be used
|
|||
|
with them, depending on exactly what the user wants. For example the 'ls'
|
|||
|
command just lists directories, if you want extra information, you have to ask
|
|||
|
for it. UNIX must have either been written by a mimimalist or someone who
|
|||
|
didn't like typing!!! It does no more and no less than it is asked to, this is
|
|||
|
something that users find quite difficult to understand.
|
|||
|
|
|||
|
The 'ls' command is the perfect example of this. In most other systems it
|
|||
|
would be called 'dir' or 'list'. The most commonly used option with 'ls' is
|
|||
|
'ls -l'. In this case the 'l' stands for 'long'. The command therefore
|
|||
|
produces a long listing of the current directory. The output looks soemthing
|
|||
|
like that shown below :-
|
|||
|
|
|||
|
drwxr_xr_x 4 Fred 96 Jun 1 10:00 cprogs
|
|||
|
drwxr_xr_x 4 Fred 195 Jul 25 09:34 memos
|
|||
|
drwxr-xr_x 2 Fred 167 Aug 14 17:29 wpfls
|
|||
|
drwxr_xr_x 2 Fred 84 May 7 07:56 sprdsht
|
|||
|
drwxr_xr_x 2 Fred 952 Jun 16 13:51 pending
|
|||
|
|
|||
|
This will tell you whether the entry is a file or a directory. The permissions
|
|||
|
(r is for read, w is for write, x is for execute), the number of links to the
|
|||
|
file, the owner, the size (in bytes), the date it was last modified, and the
|
|||
|
name of the entry. Options for the commands are sometimes (not always)
|
|||
|
preceeded with a minus sign and they usually consist of a letter which usually
|
|||
|
stands for something. The reason for this vagueness in the format of UNIX is
|
|||
|
that UNIX has evolved through time and commands have been written by a variety
|
|||
|
of people from a variety of places so there are no hard and fast rules - this
|
|||
|
is another thing that newcomers to UNIX find frustrating. It would be true to
|
|||
|
say that for each one of the 'rules' mentioned above, there are exceptions.
|
|||
|
There are also special commands for adding and removing directories from the
|
|||
|
directory structure. They are 'rmdir' for removing directories and 'mkdir' for
|
|||
|
making directories. They both expect a Pathname as a parameter which is the
|
|||
|
name of the directory to be created or removed. For example, to create the
|
|||
|
directory 'letters' below the directory 'wpfls' from Fred's HOME directory :-
|
|||
|
|
|||
|
$mkdir wpfls/letters
|
|||
|
|
|||
|
To remove this directory :-
|
|||
|
|
|||
|
$rmdir wpfls/letters
|
|||
|
|
|||
|
The command 'rmdir' will only remove empty directories, that is directories
|
|||
|
which do not contain files or sub-directories.
|
|||
|
|
|||
|
Every directory in UNIX has two hidden entries, these are '.'(dot) and '..'
|
|||
|
(dot-dot). These are created when the directory is created. '.' references
|
|||
|
the current directory and '..' references the directory above the current
|
|||
|
directory (called the Parent directory). These two directories are in fact the
|
|||
|
key to the way the whole file system is put together. They can be seen by
|
|||
|
using the '-a' option in the 'ls' command (i.e. 'ls -al') and they can also be
|
|||
|
used in relative pathnames. For example :-
|
|||
|
|
|||
|
$cd ../wpfls
|
|||
|
|
|||
|
from the directory 'sprdsht' in Fred's HOME directory is a perfectly acceptable
|
|||
|
command.
|
|||
|
|
|||
|
With these commands many generations of UNIX users have had their first
|
|||
|
foot-hold on UNIX. If you have any UNIX problems or comments to make then
|
|||
|
please leave me (MINOTAUR) a message on the Hackernet BBS.
|
|||
|
|
|||
|
Minotaur.
|
|||
|
|
|||
|
===============================================================================
|
|||
|
[Hackernet BBS,LEEDS,UK(0532)557739, 24hrs. Home of H-Net Hacking magazine]
|
|||
|
|