You are on page 1of 12

Unix

History:

The origin of unix can be traced back to 1965, when a join venture was undertaken by Bell Telephone
Laboratories, the General Electirc company and Massachusetts Institute of Technology. The aim was to
develop an operating system that could serve a large community of users and allow them to share data.

This enterprise was called MULTICS, for Multiplex Information and computing service. But the attempt
was failed, so Dennis Ritcheie and Ken thompson, both of AT & T, to start afresh on what their mind’s
eye has so illustriously envisioned. Thus, in 1969, two slong with a few others evolved what was to be the
first version of multi user sysem UNIX which was deploye on PDP-7 (a very minimal configuration
system). This system was named by Brian Kernighan who belonged to MULTICS. Later in 1971 unix
was ported to a PDP-11 computer with a 512KB disk. Unix then was a 16kb system with 8kb for user
programs and a upper limit of 64kb perfile. All its assembly code was machine dependent, the version
was not at all portable, which is a key requirement for a successful OS.

To overcome this, Ken Thompson created a new language ‘B’ and set about the Herculean task of
rewriting the whole unix code in this high level language. But ‘B’ lacked in several aspects necessary for
real lie programming. Ritchie eyed on this and modified ‘B’ to the next level and named it as ‘C’, the
language which finally enabled UNIX to work on any machine.

By 1973 Unix had come a long way and was soon licensed to quite a number of Universities, companies
and other commercial institutions.

By the Mid eighties there were more than a hundred thousand Unix installations running on anything
from a micro to a mainframe computer.

The H/W requirements of Unix in 80’s used be 80MB hard disk, 4MB RAM, 16-bit Microprocessor
(80286/80386/80486).
Features of Unix:

Multiuser capability: In multiuser system, the same computer resources (HDD,RAM etc) are shared by
many users. Users connect to the host thru terminals using VTERM, XTALK

Multitasking Capability: This is managed by dividing the CPU time intelligently between all processes
being carried out. Depending on the priority of the task, the operating system appropriately allots small
time slots to each foreground and background task.

Communication: It provides excellent provision for communicating with fellow users. The
communication may be within the network of a single main computer or between two or more such
computer networks. The users can easily exchange mail , data, programs through such networks.

Security: Unix has three inherent provisions for protecting data. The first is provided by assigning
passwords and login names to individual users ensuring that not anybody can come and have access to
your work.

At file level, there are read, write and execute permissions to each file which decide who can access a
particular file, who can modify it and who can execute it. You may reserve read and write permissions for
yourself and leave others on the network free to execute it, or any such combination.
Lastly, there is file encryption. This utility encodes your file into an unreadable format, so that even if
someone succeeds in opening it, your secrets are safe.

Portability: One of the main reasons for the universal popularity of Unix is that it can be ported to almost
any computer system, with only the min. of adaptations to suit the given computer architecture. Actually
the credit for this feature must be given to the Dennis Ritchie’s C. Unix in fact is almost entirely written
in C.

Unix System Architecture:

The function of Unix is manned in three levels. On the outer crust reside the application programs, and
other utilities, which speak our language. At the heart of Unix, on the other hand, is the Kernel, which
interacts with the actual hardware in machine language. The streamlining of these two modes of
communication is done by the middle layer called the SHELL.

The Shell or the command interpreter as it is called, is the mediator, which interprets the commands that
we give and then conveys them to the kernel which ultimately executes them. We can relate KERNEL as
monarch, and SHELL as its emissary.
The KERNEL has various functions, like managing files, data transfer between the file system and the
hardware, managing memory, scheduling of various programs, allocation of CPU time to all running
programs, handling interrupts issued.

The KERNEL program is usually stored in a file called ‘unix’ whereas the shell program is in a file called
‘sh’. For each user working with Unix at any time different shell programs are running. Thus, at a
particular point in time there may be several shells running in memory but only one KERNEL. This is
becoz, at any instance Unix is capable of executing only one program as the other programs wait for their
turn. And since it’s the kernel which executes the program one kernel is sufficient. However different
users at different terminals are trying to seek kernel’s attention. And since the user interacts with kernel
through the shell different shells are necessary.

Unix File System: Unix treats everything it knows and understands, as a file. All utilities, applications,
data in Unix is stored as files. Even a directory is treated as a file which contains several other files. The
unix file system simply resembles a upside down tree. So, the file system begins with a directory called
root. The root directory is denoted as slash (/). Branching from the root there are several other directories
called bin,lib,usr,etc,tmp, var and dev. The root directory also contains a file called unix which is unix
kernel itself.

The main reason behind creation of directories is to keep related files together and separate them from
other group of related files. For example, it is a good idea to keep all user related files in the usr directory,
all device related files in the dev directory, all temporary files in the tmp directory and so on.

The bin directory contains executable files for most of the unix commands. Unix commands can be either
C programs or shell programs. Shell programs are nothing but an collection of several Unix commands.

The lib directory contains all the library functions provided by Unix for programmers. The programs
written under Unix make use of these library functions in the lib directory.

The dev directory contains files that control various input/output devices like terminals, printer, disk
drivers etc. For each device there is a separate file. In unix each device is implemented as file.

In usr directory there are several directories, each associated with a particular user. These directories are
created by the system administrator when he creates accounts for different users.

The tmp directory contains the temporary files created by Unix or by the users.

var - Stores log files, mails and other data

Supported file systems:

• Ext2: This is like UNIX file system. It has the concepts of blocks, inodes and directories.
• Ext3: It is ext2 filesystem enhanced with journalling capabilities. Journalling allows fast
file system recovery. Supports POSIX ACL (Access Control Lists).
• Isofs (iso9660): Used by CDROM file system.
• Sysfs: It is a ram-based filesystem initially based on ramfs. It is use to exporting kernel
objects so that end user can use it easily.
• Procfs: The proc file system acts as an interface to internal data structures in the kernel. It
can be used to obtain information about the system and to change certain kernel
parameters at runtime using sysctl command. For example you can find out cpuinfo with
following command:

Again file system divided into two categories:

• User data - stores actual data contained in files


• Metadata - stores file system structural information such as superblock, inodes,
directories
Unix / Linux filesystem blocks
The blocks used for two different purpose:

1. Most blocks stores user data aka files (user data).


2. Some blocks in every file system store the file system's metadata. In simple words
Metadata describes the structure of the file system. Most common metadata structure are
superblock, inode and directories. Following paragraphs describes each of them.

Superblock
Each file system is different and they have type like ext2, ext3 etc. Further each file system has
size like 5 GB, 10 GB and status such as mount status. In short each file system has a superblock,
which contains information about file system such as:

• File system type


• Size
• Status
• Information about other metadata structures

If this information lost, you are in trouble (data loss) so Linux maintains multiple redundant
copies of the superblock in every file system. This is very important in many emergency
situation, for example you can use backup copies to restore damaged primary super block.
Following command displays primary and backup superblock location on /dev/sda3:

Understanding UNIX / Linux filesystem Inodes

The inode (index node) is a fundamental concept in the Linux and UNIX filesystem. Each
object in the filesystem is represented by an inode. But what are the objects? Let us try to
understand it in simple words. Each and every file under Linux (and UNIX) has following
attributes:

=> File type (executable, block special etc)


=> Permissions (read, write etc)
=> Owner
=> Group
=> File Size
=> File access, change and modification time (remember UNIX or Linux never stores file
creation time, this is favorite question asked in UNIX/Linux sys admin job interview)
=> File deletion time
=> Number of links (soft/hard)
=> Extended attribute such as append only or no one can delete file including root user
(immutability)
=> Access Control List (ACLs)
All the above information stored in an inode. In short the inode identifies the file and its
attributes (as above) . Each inode is identified by a unique inode number within the file system.
Inode is also know as index number.

inode definition
An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An inode
stores basic information about a regular file, directory, or other file system object.
Commands: Unix/Linux commands are strictly case sensitive

Help on any Unix command

man {command} Type man ls to read the manual for the ls command.

whatis {command} Give short description of command

apropos {keyword} Search for all Unix commands that match keyword, eg apropos

file

Knowing about yourself

who Displays all about the users who logged into the system
currently.

who am i Displays about the current user

Creating files

touch {filename} creates a zero byte file.

cat > {filename} Creates a file in edit mode where in any text can be typed, to
save the contents and exit press CTRL+D.

eg: cat file1 file2 > file 3 (creates file3 with file1 and file2 contents)

cat file1 file2 >> file3 (Adds the contents of file1 and file2 to file3)

Make a new directory

mkdir {dirname}

List a directory

ls {path} It's ok to combine attributes, eg ls -laF gets a long listing of all files with types.

ls {path_1} {path_2} List both {path_1} and {path_2}.

ls -l {path} Long listing, with date, size and permisions.

ls -a {path} Show all files, including important .dot files that don't otherwise show.

ls -F {path} Show type of each file. "/" = directory, "*" = executable.

ls -R {path} Recursive listing, with all subdirs.


ls {path} > {filename} Redirect directory to a file.

ls {path} | more Show listing one screen at a time.

dir {path} Useful alias for DOS people, or use with ncftp.

Change to directory

cd {dirname} There must be a space between.

cd ~ Go back to home directory, useful if you're lost.

cd .. Go back one directory.

cdup Useful alias, like "cd ..", or use with ncftp.

Remove a directory

rmdir {dirname} Only works if {dirname} is empty.

rm -r {dirname}Remove all files and subdirs. Careful!

Print working directory

pwd Show where you are as full path. Useful if you're lost or exploring.

Copy a file or directory

cp {file1} {file2}

cp -r {dir1} {dir2} Recursive, copy directory and all subdirs.

cat {newfile} >> {oldfile} Append newfile to end of oldfile.

Move (or rename) a file

mv {oldfile} {newfile} Moving a file and renaming it are the same thing.

mv {oldname} {newname}

Delete a file

rm {filespec} ? and * wildcards work like DOS should. "?" is any character; "*" is any string of
characters.

View a text file

more {filename} View file one screen at a time.

less {filename} Like more, with extra features.


cat {filename} View file, but it scrolls.

cat {filename} | more View file one screen at a time.

page {filename} Very handy with ncftp.

pico {filename} Use text editor and don't save.

Edit a text file.

pico {filename} The same editor PINE uses, so you already know it. vi and emacs are also
available.

Compare two files

diff {file1} {file2} Show the differences.

sdiff {file1} {file2} Show files side by side.

Other text commands

grep '{pattern}' {file} Find regular expression in file.

sort {file1} > {file2} Sort file1 and save as file2.

sort -o {file} {file} Replace file with sorted version.

spell {file} Display misspelled words.

wc {file} Count words in file.

Find files on system

find {filespec} Works with wildcards. Handy for snooping.

find {filespec} > {filename} Redirect find list to file. Can be big!

Make an Alias

alias {name} '{command}' Put the command in 'single quotes'. More useful in your .cshrc
file.

Wildcards and Shortcuts

* Match any string of characters, eg page* gets page1, page10, and page.txt.

? Match any single character, eg page? gets page1 and page2, but not page10.

[...] Match any characters in a range, eg page[1-3] gets page1, page2, and page3.

~ Short for your home directory, eg cd ~ will take you home, and rm -r ~ will destroy it.
. The current directory.

.. One directory up the tree, eg ls ...

You might also like