0% found this document useful (0 votes)
3 views

unix-1

Uploaded by

kanchanaketha06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

unix-1

Uploaded by

kanchanaketha06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

UNIT-1

Introduction to UNIX
Why UNIX:
● UNIX operating system was designed to access the computer by a number of
programmers at the same time and share its resources.

● UNIX operating system provides an environment more powerful and flexible and is
found in businesses, sciences, academia, and industry.

● Many telecommunication switches and transmission systems also are controlled by


administration and maintenance systems based on UNIX.

● UNIX is most widely used in all forms of computing systems such as desktop, laptop,
and servers.

History of UNIX:
● UNIX development was started in 1969 at Bell Laboratories in New Jersey, aimed for
a multi-user, time-sharing operating system called Multics (Multiplexed Information
and Computing System) but it was failed.

● Ken Thompson and Dennis Ritchie again rewrite an operating system on smaller
machine known as UNICS (Uniplexed Information and Computing Service).

● The first version of Unix was written in the low-level PDP-7 assembler language,
later a language called TMG was developed for the PDP-7 to develop a FORTRAN
compiler.

● UNIX components were later rewritten in C, kernel in 1973. Unix V6, released in
1975 became very popular and free. In 1983, AT&T released Unix System V which
was a commercial version.

● Berkeley took initiative on its own Unix BSD (Berkeley Software Distribution) Unix.
Sun Microsystems developed its own BSD-based Unix called SunOS and later was
renamed to Sun Solaris.

● Microsoft and the Santa Cruz operation (SCO) were involved in another version of
UNIX called XENIX. Hewlett-Packard developed HP-UX for its workstations. DEC
released ULTRIX.
What is UNIX?
● It is a multi-user system where the same resources can be shared by different users.

● It provides multi-tasking, wherein each user can execute many processes at the same
time.

● It was the first operating system that was written in a high-level language (C
Language).

● It provides a hierarchical file structure which allows easier access and maintenance of
data.

● Unix has built-in networking functions so that different users can easily exchange
information.

● Unix functionality can be extended through user programs built on a standard


programming interface.

UNIX Components (Architecture):


● The Architecture of Unix Operating system is shown as follows:

● There are four major layers in Unix Architecture such as follows:

● Layer-1: Hardware – It consists of all hardware related information.

● Layer-2: Kernel –It interacts with hardware and most of the tasks like memory
management, task scheduling, and management are done by the kernel.
● Layer-3: Shell commands – Shell is the utility that processes your requests. When you
type in a command at the terminal, the shell interprets the command and calls the
program that you want.

● Layer-4: Application Layer – It is the outermost layer that executes the given external
applications.

Applications of UNIX:
● UNIX is useful everywhere and anywhere such as Network management, telco,
internet, banking, shipping, security, military, factory automation.

● UNIX is also available as Your android phone

● Your router at home

● Your Apple mac

● Your super Flat TV

● Your digital camera

● Your GPS.

● The role Internet plays these days and over 90% servers use Linux including the
giants like Facebook and Google.

● The big players, such as Oracle (company) and SAP (company), run on Unix. While
they can also run on Windows servers, Unix is more manageable.

● Unix based operating systems are stable, secure and handle multi-user systems .Unix
based operating systems are designed to run for long periods of time with minimal
shutdown.

● Unix is designed to handle multiple users , they are mostly designed to be able to run
on servers with desktops running on top of the server.

● Generally Unix based systems are much more stable compared to Windows. It is
possible that a Unix server uses almost 100% CPU and still be able to run applications
without getting a breakdown.

● Banks have to run long running batch programs routinely with millions of records of
data getting updated for critical operations such as interest calculation. .

● Full multitasking with protected memory. Multiple users can run multiple programs
each at the same time without interfering with each other or crashing the system.

● Very efficient virtual memory, so many programs can run with a modest amount of
physical memory.
● All users must be authenticated by a valid account and password to use the system at
all. All files are owned by particular accounts. The owner can decide whether others
have read or write access to his files.

● Banks use various software for their day to day operations, and also contains
confidential information regarding customers. So they must keep their network
secure. And thus banks use intranet rather than internet.

● UNIX OS are not prone to viruses, Trojans, malware, ransomwares, thus few banks
may run on UNIX platform .

● Most of the software nowadays is deployed in the cloud or is a mobile app. Most
cloud applications run on a UNIX stack. Most mobile apps run on iOS or Android.

Commands in UNIX:
➢ Commands are generally used for file management in UNIX. The following are the
some of the basic commands in UNIX:

● Listing files (ls): If you want to see the list of files on your UNIX or Linux system,
use the 'ls' command. It shows the files /directories in your current directory.

● You can use 'ls -R' to shows all the files not only in directories but also subdirectories.

● 'ls -al' gives detailed information of the files.

● Hidden items in UNIX/Linux begin with period symbol.

➢ Creating & Viewing Files: The 'cat' command is used to display text files. It can also
be used for copying, combining and creating new text files.
➢ To create a new file, use the command

1. cat > filename

2. Add content

3. Press 'ctrl + d' to return to command prompt

➢ Example:

• The syntax to combine 2 files is - cat file1 file2 > newfilename

Example:

➢ Deleting Files: The 'rm' command removes files from the system without
confirmation.

Syntax: rm filename

Example:

➢ Creating Directories: Directories can be created on a Linux operating system using


the following command.

Syntax: mkdir directoryname

Example:
➢ Removing Directories: To remove a directory, use the command-

Syntax: rmdir directoryname

Example:

➢ Renaming Directory: The 'mv' (move) command (covered earlier) can also be used for
renaming directories.

Syntax: mv directoryname newdirectoryname

Example:

➢ Man command: Man stands for manual which is a reference book of a Linux
operating system.

Syntax: $man man

Example:
➢ History Command: History command shows all the commands that you have used in
the past for the current terminal session.

Example:

➢ Clear command: This command clears all the clutter on the terminal and gives you a
clean window

Syntax: $ Clear

Example:

➢ Date Command: The date command displays the current day, date, time, and year.

Syntax: $date

➢ Df Command: This command reports file system disk usage

Syntax: $df

➢ Du Command: This command reports disk usage (that is, the amount of space taken
up by a group of files).

Syntax: $du

➢ Pwd Comand: This command reports the current directory path.

Syntax: $pwd

Command Substitution:
● Command substitution allows the output of a command to replace the command itself.
Command substitution occurs when a command is enclosed as follows:

Syntax: $(command) or `command`

● Command substitution allows you to capture the output of any command as an


argument to another command.

● When you place a command line within backquotes (``), the shell first runs the
command or commands and then replaces the entire expression, including the
backquotes, with the output.

● For example, the statement: today=`date` Assigns the string representing the current
date to the today variable.

Example: files=`ls | wc -l`

● The assignment saves, in the files variable, the number of files in the current
directory.

● To nest command substitutions, precede each of the nested backquotes with a


backslash (\), as in:

logmsg=`echo Your login directory is \`pwd\``

● You can also give values to shell variables indirectly by using the read special
command.

● For example:

Giving multiple commands (Command chaining):


● Combining two or more commands on the command line is also known as “command
chaining”.

We can combine commands on the command line in different ways such as:

1) The semicolon operator 2) The logical AND operator 3) The logical OR operator

1) The semicolon operator: The semicolon (;) operator allows you to execute multiple
commands in succession, regardless of whether each previous command succeeds. For
example, type the following three commands on one line, separated by semicolons, and press
Enter.
Syntax: ls ; pwd ; whoami

Example:

2) The logical AND operator: If you want the second command to only run if the first
command is successful, separate the commands with the logical AND operator, which is two
ampersands ( && ).

Syntax: mkdir MyFolder && cd MyFolder

Example:

● The folder was successfully created, so the cd command was executed and we are
now in the new folder

3) The logical OR operator: Sometimes you might want to execute a second command
only if the first command does not succeed. To do this, we use the logical OR operator, or
two vertical bars ( || ).

Syntax: [ -d ~/MyFolder ] || mkdir ~/MyFolder

Example:

● Note: In our example, the MyFolder directory does not exist, so the second command
creates the directory.
The File System-
The Basics of Files:
● A file is a smallest unit in which the information is stored. All data in Unix is
organized into files. All files are organized into directories. These directories are
organized into a tree-like structure called the file system.

● Files in Unix System are organized into multi-level hierarchy structure known as a
directory tree. At the very top of the file system is a directory called “root” which is
represented by a “/”. All other files are “descendants” of root.

● / : The slash / character alone denotes the root of the filesystem tree.

● /bin : Stands for “binaries” and contains certain fundamental utilities, such as ls or cp.

● /boot : Contains all the files that are required for successful booting process.

● /dev : Stands for “devices”. Contains file representations of peripheral devices and
pseudo-devices.

● /etc : Contains system-wide configuration files and system databases.

● /home : Contains the home directories for the users.

● /lib : Contains system libraries, and some critical files such as kernel modules or
device drivers.

● media : Default mount point for removable devices, such as USB sticks, media
players, etc.
● /mnt : Stands for “mount”. Contains filesystem mount points.These are used for hard
disk partitions, remote (network) filesystems, CD-ROM/DVD drives,

● /proc : procfs virtual filesystem showing information about processes as files.

● /root : The home directory for the superuser “root” – that is, the system administrator.

● /tmp : A place for temporary files.

● /usr : Originally the directory holding user home directories.

● /usr/bin : This directory stores all binary programs distributed with the operating
system not residing in /bin, /sbin or (rarely) /etc.

Types of UNIX files:

1. Ordinary files – An ordinary file is a file on the system that contains data, text, or program
instructions.In long-format output of ls -l, this type of file is specified by the “-” symbol.

2. Directories – Directories store both special and ordinary files. A directory file contains an
entry for every file and subdirectory. Each entry has two components. The Filename, A
unique identification number for the file or directory (called the inode number).In long-
format output of ls –l , this type of file is specified by the “d” symbol.

3. Special Files – Used to represent a real physical device such as a printer, tape drive or
terminal, used for Input/output (I/O) operations. There are two flavors of special files for each
device, character special files and block special files. In long-format output of ls -l, character
special files are marked by the “c” symbol. In long-format output of ls -l, block special files
are marked by the “b” symbol.

4. Pipes – UNIX allows you to link commands together using a pipe. The pipe acts a
temporary file which only exists to hold data from one command until it is read by another.
Example: who | wc -l.
5. Sockets – A Unix socket (or Inter-process communication socket) is a special file which
allows for advanced inter-process communication. A Unix Socket is used in a client-server
application framework.In long-format output of ls -l, Unix sockets are marked by “s” symbol.

6. Symbolic Link – Symbolic link is used for referencing some other file of the file system.
Symbolic link is also known as Soft link. In long-format output of ls –l , Symbolic link are
marked by the “l” symbol.

Permissions:
➢ Every file and directory in your UNIX/Linux system has following 3 permissions.

● Read: This permission give you the authority to open and read a file.

● Write: The write permission gives you the authority to modify the contents of a
file. The write permission on a directory gives you the authority to add, remove
and rename files stored in the directory.

● Execute: In Unix/Linux, you cannot run a program unless the execute


permission is set.

Example:

● Here, the first '-' implies that we have selected a file.


● Else, if it were a directory, d would have been shown.

➢ The first part of the code is 'rw-'. This means the owner can:

● Read the file

● Write or edit the file

● He cannot execute the file since the execute bit is set to '-'

➢ Example:

➢ The second part is 'rw-'. It for the user group 'Home' and group-members can:

● Read the file

● Write or edit the file

➢ The third part is for the world which means any user. It says 'r--'. This means the user
can only:

● Read the file

Inodes:
➢ An Inode number is a uniquely existing number for all the files in Linux and all Unix
type systems.When a file is created on a system, a file name and Inode number is
assigned to it.

➢ An Inode is a data structure containing metadata about the files .Following contents
are stored in the Inode from a file:

● User ID of file
● Group ID of file

● Device ID

● File size

● Date of creation

● Permission

● Owner of the file

● File protection flag & Link counter to determine number of hard links

➢ Inode Table: The Inode table contains all the Inodes and is created when file system is
created. The df -i command can be used to check how many inodes are free and left
unused in the filesystem.

Example:

➢ Inode Number: Each Inode has a unique number and Inode number can be seen with
the help of ls -li command.

Example:

The below figure illustrates the structure of the inode:


Fig: Inode Structure

You might also like