0% found this document useful (0 votes)
15 views12 pages

Chapter 2 Introduction To UNIX Concepts

Chapter 2 provides an introduction to the Unix operating system, covering its features, architecture, file system, and process environment. Key aspects include Unix's multiuser and multitasking capabilities, its command structure, and basic commands like echo, printf, and ls. The chapter also discusses the Unix file system organization and how processes are managed within the system.

Uploaded by

Manisha Rathod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Chapter 2 Introduction To UNIX Concepts

Chapter 2 provides an introduction to the Unix operating system, covering its features, architecture, file system, and process environment. Key aspects include Unix's multiuser and multitasking capabilities, its command structure, and basic commands like echo, printf, and ls. The chapter also discusses the Unix file system organization and how processes are managed within the system.

Uploaded by

Manisha Rathod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Chapter 2

Introduction To Unix
Concepts
By-RAHUL SONAWANE CA - CCTP-5 OPERATING SYSTEMS
0
Chapter 2 Introduction to UNIX concepts.
1. Introduction to Unix Operating System.
2. Features of Unix.
3. Architecture of the Unix Operating System.
4. Introduction to File System and Process Environment.
5. Working with Unix
• The login prompt.
• General features of Unix commands/ command structure.
• Command arguments and options.
• Understanding of some basic commands such as echo, printf, ls, who, date, passwd,
cal, Combining commands.

1. Introduction
• UNIX is an operating system.
• An operating system is a set of programs that act as a link between the computer and the user.
• The operating system (OS) manages the resources of a computer.
• Examples of computer resources are: CPU, RAM, disk memory, printers, displays, keyboard,
etc.

Figure 1.1 : Operating System

• UNIX OS allows complex tasks to be performed with a few keystrokes.


• UNIX OS doesn’t tell or warn the user about the consequences of the command.
• Unix was originally developed in 1969 by a group of AT&T employees Ken Thompson,
Dennis Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs.
• There are various Unix variants available in the market.
• Solaris Unix, AIX, HP Unix and BSD are a few examples.
• Linux is also a flavor of Unix which is freely available.

2. Features of Unix
1) Multiuser
• UNIX is a multiprogramming system.
• Multiple users can access the system by connecting to points known as terminals.
• Several users can run multiple programs simultaneously on one system.

CA - CCTP-5-Operating Systems 1
2) Multitasking
• UNIX is a multitasking system.
• A single user can also run multiple tasks concurrently.
• For example:
At the same time, a user can
→ edit a file
→ print another file one on the printer
→ send email to a friend and
→ browse www
• The kernel is designed to handle a user's multiple needs.
• In a multitasking environment, a user sees one job running in the foreground; the rest run in
the background.
• User can switch jobs between background and foreground, suspend, or even terminate them.
3) Pattern Matching
• UNIX has very sophisticated pattern matching features.
• Regular Expressions are a feature of UNIX.
• Regular Expressions describe a pattern to match, a sequence of characters, not words, within a
line of text.
4) Portable
• UNIX can be installed on many hardware platforms.
• Unix operating system is written in C language; hence it is more portable than other operating
systems.
5) UNIX Toolkit
• UNIX offers facility to add and remove many applications as and when required.
• Tools include
→ general purpose tools
→ text manipulation tools
→ compilers/interpreters
→ networked applications and
→ system administration tools
6) Programming Facility
• The UNIX shell is also a programming language; it was designed for programmer, not for end
user.
• It has all the necessary ingredients, like control structures, loops and variables, that establish
powerful programming language.
• These features are used to design shell scripts – programs that can also invoke UNIX
commands.
• Many of the system's functions can be controlled and automated by using these shell scripts.
7) Documentation
• The principal on-line help facility available is the man command, which remains the most
important references for commands and their configuration files.
• Apart from the man documentation, there's a vast ocean of UNIX resources available on the
Internet.

CA - CCTP-5-Operating Systems 2
3. Unix Architecture (Components)
• The UNIX operating system (OS) consists of a kernel layer, a shell layer, an application layer
& file.

Figure 1.2 : Unix Architecture

Kernel
• The kernel is the heart of the operating system.
• It interacts with the machine’s hardware.
• It is a collection of routines written in C.
• It is loaded into memory when the system is booted.
• Main responsibilities:
1) Memory management
2) Process management (using commands: kill, ps, nohup)
3) File management (using commands: rm, cat, ls, rmdir, mkdir)
• To access the hardware, user programs use the services of the kernel via system calls.
System Call
• A system call is a request for the operating system to do something on behalf of the user's
program.
• The system calls are functions used in the kernel itself.
• To the programmer, the system call appears as a normal C function call.
• UNIX system calls are used to manage the file system and control processes.
Example: read(), open(), close(), fork(), exec(), exit()
• There can be only one kernel running on the system.

Shell
• The shell interacts with the user.
• The shell is a command line interpreter (CLI).
• Main responsibilities:
1) interprets the commands the user types in and

CA - CCTP-5-Operating Systems 3
2) dispatches the command to the kernel for execution
• There can be several shells in action, one for each user who’s logged in.
• There are multiple shells that are used by the UNIX OS.
• For example: Bourne shell (sh), the C shell (csh), the Korn shell (ksh) and Bourne Again shell
(bash).
Application
• This layer includes the commands, word processors, graphic programs and database
management programs.
File
• A file is an array of bytes that stores information.
• All the data of Unix is organized into files.
• All files are then organized into directories.
• These directories are further organized into a tree-like structure called the filesystem.

4. Introduction to File System and Process Environment.


4.1. File System
• Unix file system is a logical method of organizing and storing large amounts of information in
a way that makes it easy to manage.
• A file can be informally defined as a collection of (typically related) data, which can be
logically viewed as a stream of bytes (i.e. characters). A file is the smallest unit of storage in
the Unix file system.
• By contrast, a file system consists of files, relationships to other files, as well as the attributes
of each file. File attributes are information relating to the file, but do not include the data
contained within a file. File attributes for a generic operating system might include (but are not
limited to):
• a file type (i.e. what kind of data is in the file)
• a file name (which may or may not include an extension)
• a physical file size
• a file owner
• file protection/privacy capability
• file time stamp (time and date created/modified)
• Additionally, file systems provide tools which allow the manipulation of files, provide a
logical organization as well as provide services which map the logical organization of files
to physical devices.
• From the beginner’s perspective, the Unix file system is essentially composed of files and
directories. Directories are special files that may contain other files.
• Unix file system has several important features. 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.

CA - CCTP-5-Operating Systems 4
• From a user perspective in a Unix system, everything is treated as a file. Even such devices
such as printers and disk drives.
• How can this be, you ask? Since all data is essentially a stream of bytes, each device can be
viewed logically as a file.
• In Unix, there are three basic types of files −
• Ordinary Files − An ordinary file is a file on the system that contains data, text, or program
instructions. In this tutorial, you look at working with ordinary files.
• Directories − Directories store both special and ordinary files. For users familiar with
Windows or Mac OS, Unix directories are equivalent to folders.
• Special Files − Some special files provide access to hardware such as hard drives, CD-ROM
drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts
and enable you to access a single file using different names.
• 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.

4.2 Process Environment.


• When you execute a program on your Unix system, the system creates a special environment
for that program. This environment contains everything needed for the system to run the
program as if no other program were running on the system.
• A program/command when executed, a special instance is provided by the system to the
process. This instance consists of all the services/resources that may be utilized by the process
under execution.

CA - CCTP-5-Operating Systems 5
• Whenever a command is issued in Unix/Linux, it creates/starts a new process. For example,
pwd when issued which is used to list the current directory location the user is in, a process
starts.
• Through a 5 digit ID number Unix/Linux keeps an account of the processes, this number
is call process ID or PID. Each process in the system has a unique PID.
• Used up pid’s can be used in again for a newer process since all the possible combinations
are used.
• At any point of time, no two processes with the same pid exist in the system because it is
the pid that Unix uses to track each process.
• Whenever you issue a command in Unix, it creates, or starts, a new process. When you tried
out the ls command to list the directory contents, you started a process. A process, in simple
terms, is an instance of a running program.
• The operating system tracks processes through a five-digit ID number known as the pid or the
process ID. Each process in the system has a unique pid.
• Pids eventually repeat because all the possible numbers are used up and the next pid rolls or
starts over. At any point of time, no two processes with the same pid exist in the system because
it is the pid that Unix uses to track each process.

5. Working with Unix:


5.1. The Login Prompt
How to log in
• Have your userid (user identification) and password ready.
• Type your userid at the login prompt, then press ENTER. Your userid is case sensitive, so be
sure you type it exactly as your system administrator has instructed.
• Type your password at the password prompt, then press ENTER. Your password is also case
sensitive.
• If you provide the correct userid and password, then you will be allowed to enter into the
system.
• While the prompt($) is displayed, you can type a command (say date).
login: kumar
kumar's password: *****
Last login: Sun Jun 14 09:32:32 2017 from 162.61.164.73
$ date
Thu Jun 25 08:30:19 MST 2017

5.2 Command Structure


• UNIX commands take the following general
< form: verb [options] [arguments] >
where verb is the command name that can take a set of optional options and one or more
optional arguments.
• Commands, options and arguments have to be separated by spaces or tabs to enable the shell
to interpret them as words.
• A contiguous string of spaces and tabs together is called a whitespace.
• The shell compresses multiple occurrences of whitespace into a single whitespace.

5.2 Options
• An option is preceded by a minus sign (-) to distinguish it from filenames.

CA - CCTP-5-Operating Systems 6
• Example:
$ ls –l // -l option list all the attributes of the file note
• There must not be any whitespaces between – and l.
• Options are also arguments, but given a special name because they are predetermined.
• Options can be normally combined with only one – sign.
thus $ ls –l –a –t is same as $ ls –lat
• Because UNIX was developed by people who had their own ideas as to what options should
look like, there will be variations in the options.
• Some commands use + as an option prefix instead of -.

5.3 Filename Arguments


• Many UNIX commands use a filename as argument so that the command can take input from
the file.
• If a command uses a filename as argument, it will usually be the last argument, after all
options.
• Example:
ls -lat chap01 chap02 chap03 # Multiple filenames as
arguments cp file1 file2 file3 dest_dir
rm file1 file2 file3

• The command with its arguments and options is known as the command line.
• This line can be considered complete only after the user has hit [Enter].
• The complete line is then fed to the shell as its input for interpretation and execution.

Exceptions
• There are some commands that don't accept any arguments.
• There are also some commands that may or may not be specified with arguments.
• For Example:
The ls command can run
→ without arguments (ls)
→ with only options (ls –l)
→ with only filenames (ls f1 f2), or
→ using a combination of both (ls –l f1 f2).
• There are some commands compulsorily take options (cut).
• There are some commands which can take an expression as an argument, or a set of
instructions as argument. Ex: grep, sed

5.4 Understanding of Some Basic Commands


1. echo
• This command can be used to display a message on the terminal.
• Example:
$ echo "Welcome to UNIX \n"
Welcome to UNIX
• This command can be used with following escape characters:
"\a" Audible Alert (Bell)

CA - CCTP-5-Operating Systems 7
"\b‟ Back Space
"\f‟ Form Feed
"\n‟ New Line
"\r‟ Carriage Return
"\t‟ Horizontal Tab
"\v‟ Vertical Tab
"\\‟ Backslash
2. printf
• This command can be used to display a message on the terminal.
• This command can be used with following escape characters:
"\a" Audible Alert (Bell)
"\b‟ Back Space
"\f‟ Form Feed
"\n‟ New Line
"\r‟ Carriage Return
"\t‟ Horizontal Tab
"\v‟ Vertical Tab
"\\‟ Backslash
• Example:
$ printf "Welcome to UNIX \n"
Welcome to UNIX
• Similar to C language, this command can be used with following format specifiers:
%d Decimal integer
%f Floating point number
%s String
%o Octal integer (base 8)
%x Hexadecimal integer (base 16)
• Syntax:
printf("format-string", variable-list);
where format-string contains one or more format-specifiers variable-list contains names of
variables
• Example:
$ printf "My current shell is %s\n" $SHELL
My current shell is /bin/ksh

3. ls
• ls command can be used to obtain a list of all filenames in the current directory.
• -l option can be used to obtain a detailed list of attributes of all files in the current directory.
• Example:
$ ls -l
Type & Perm Link Owner Group Size Date & Time File Name
-rwxr-xr-- 1 kumar metal 195 may 10 13:45 chap01
drwxr-xr-x 2 kumar metal 512 may 09 12:55 helpdir
4. who
• This command can be used to display the details of all the users logged-in into the unix system
at the same time.

CA - CCTP-5-Operating Systems 8
• Example:
$ who
Kumar tty0 Oct 8 14:10

Rama tty2 Oct 4 09:08


• –H option can be used to display the header information.
• Example:
$ who
NAME LINE TIME COMMENT
kumar tty0 Oct 8 14:10
Rama tty2 Oct 4 09:08
• -u option can be used to display detailed information of users.
• Example:
$ who -Hu NAME
LINE TIME IDLE PID COMMENT
kumar tty0 Oct 8 14:10 00:18 185
Rama tty2 Oct 4 09:08 00:23 123

5. date
• This command can be used to display the current date and time.
• Example:
$ date
Mon Sep 4 16:40:02 IST 2021
• This command can also be used with suitable format specifiers as arguments.
• Following are some format specifiers:
d – day of month (1 - 31)
m - Month (01-12)
y – last two digits of the year.
H– hour (00-24)
M – minute (00-59)
S – second (00-59)
D – date in the format mm/dd/yy
T – time in the format hh:mm:ss
• Syntax:
$ date +%format_specifier
• Example:
$ date +"%d-%m-%y"
04-09-21
$ date +%m // displays month number
09

6. passwd
• This command can be used to change user password.
• All Unix systems require passwords to help ensure that your files and data remain secure from
hackers.

CA - CCTP-5-Operating Systems 9
• Following are the steps to change your password –
1) To start, type password at the command prompt as shown below.
2) Enter your old password, the one you're currently using.
3) Type in your new password.
4) You must verify the password by typing it again.
$ passwd
Changing password for
kumar (current) Unix
password: ***** New
Unix password: *****
Retype new Unix
password: *****
passwd: all authentication tokens updated successfully
$

7. cal
• This command can be used to display the calendar of the current month.
• Syntax:
cal [ [ month] year ]
• Example:
$ cal
September 2017
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
• This command can also be used to display the calendar of any specific month or a complete
year.
• Example:
$ cal 9 2017
September 2017
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

• You can't hold the calendar of a year in a single screen page; it scrolls off rapidly to end of
the year.
• To pause at each screen page, a pipe "|" can be connected to more pager:
• Example:
$cal 2017 | more

1.8 Flexibility of Command Usage


• UNIX provides flexibility in using the commands.

CA - CCTP-5-Operating Systems 10
• A command can often be entered in more than one way.
• Shell allows the following type of command usage:
1) Combining Commands.
2) A command line can overflow or Be split into multiple lines.
3) Entering a command before previous command has finished.

1) Combining Commands
• UNIX allows you to specify more than one command in the single command line.
• Example:
$ wc sample.txt ; ls –l sample.txt 2 3 //Two commands separated by ; (semicolon).
16 sample.txt

-rw-rw-r-- 1 kumar group 16 Jan 30 09:35 sample.txt

$ ls | wc //Two commands combined here using filter


• You can even group several commands together so that their combined output is redirected to
a file.
(wc sample.txt ; ls –l sample.txt) > newfile
• When a command line contains a semicolon, the shell understands that the command on each
side of it needs to be processed separately. Here ; is known as a metacharacter.

2) A Command line can be split into multiple lines


• UNIX terminal width is restricted to maximum 80 characters.
• Shell allows command line to overflow or be split into multiple lines.
• Example:
$ echo “This is // $ first prompt
> a three-line // > is a secondary prompt
> text message” // Command
line ends here This is a three-line text message

3) Entering a Command before previous command has finished


• You need not have to wait for the previous command to finish before you can enter the next
command.
• Subsequent commands can be entered at the keyboard without waiting for prompt.
• The input remains stored in a buffer maintained by kernel for all keyboard input.
• The next command is passed on to the shell for interpretation after the previous program has
completed.

CA - CCTP-5-Operating Systems 11

You might also like