Monday, March 31, 2008

UNIX






The UNIX operating system is made u
p of three parts; the kernel, the shell and the programs.

The kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.

As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.

The shell
The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).

Files and processes
Everything in UNIX is either a file or a process.
A process is an executing program identified by a unique PID (process identifier).
A file is a collection of data. They are created by users using text editors, running compilers etc.
Examples of files:
a document (report, essay etc.)
the text of a program written in some high-level programming language
instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file);
a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.
The Directory Structure
All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash / )


The full path to the file report.doc is "/home/its/ug1/ee51vn/report.doc"


Listing files and directories
ls (list)
The ls command lists the contents of your current working directory.

There may be no files visible in your home directory, in which case, the UNIX prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator when your account was created.

Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information.

% ls -a
To list all files in your home directory including those whose names begin with a dot,files that are normally hidden

mkdir (make directory)
To make a subdirectory called unixstuff in your current working directory type

% mkdir unixstuff

cd (change directory)
To change to the directory you have just made, type

% cd unixstuff

The current directory (.)
In UNIX, (.) means the current directory, so typing
% cd .

The parent directory (..)
(..) means the parent of the current directory, so typing

% cd ..

will take you one directory up the hierarchy (back to your home directory).

Note: typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system.

pwd (print working directory)
to find out the absolute pathname of your home-directory, type cd to get back to your home-directory and then type
% pwd

The full pathname will look something like this -
/home/its/ug1/ee51vn

which means that ee51vn (your home directory) is in the sub-directory ug1 (the group directory),which in turn is located in the its sub-directory, which is in the home sub-directory, which is in the top-level root directory called " / " .

Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing

% ls ~/unixstuff

will list the contents of your unixstuff directory, no matter where you currently are in the file system.

cp (copy)
cp file1 file2
is the command which makes a copy of file1 in the current working directory and calls it file2

mv (move)
mv file1 file2 moves (or renames) file1 to file2

rm (remove), rmdir (remove directory)
% rm tempfile.txt

clear (clear screen)
% clear
This will clear all text and leave you with the % prompt at the top of the window.

cat (concatenate)
The command cat can be used to display the contents of a file on the screen. Type:
% cat science.txt

http://www.ee.surrey.ac.uk/Teaching/Unix/unix2.html