2020.04.02 - UNIX Shell 1 - Lecture

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

University American College Skopje

School of Computer Science and Information Technology


Course: Systems Software

UNIX Shell 1

Lecture

Prepared by: Adrijan Božinovski PhD

4/1/2020 1
A Computer System Shell
• A computer system has various kinds of users:
– Some create software on it;
– Others manipulate databases;
– Yet others just use data stored on it;
– Etc…
• Still, they all must have certain knowledge of
the operating system, to be able to use it.
• The shell of an operating system is an interface
between the operating system and the user.
Layers of an Operating System
Shell 1

C compiler

Editor 1
Libraries

Kernel
HW Software
development
Input /
output
File system

Editor 2

Shell 2
Layers of an Operating System
• The lowest layer of an operating system is the
kernel, which is immediately above the
hardware.
– It enables working with the terminals,
communication lines and other system devices.
– It enables process management and resource
distribution among the processes.
– This layer is written in an assembler and C in UNIX
operating systems.
• Analogously, the first version of the Linux kernel was
compiled in C as well.
Layers of an Operating System
• The file system is placed on the second layer.
– System libraries;
– Data support of the input and output.
• The third layer is a layer for application
development by the user.
– Using editors, compilers, linkers, debuggers, and
so on, it enables the development of executable
programs.
– The default language in UNIX is C, and other
languages can be installed if needed.
Layers of an Operating System
• The fourth layer are the shells.
– Those are textual and graphical user interfaces.
– Through them the user communicates with the
operating system.
– They assign commands to the operating system,
that the operating system carries out.
Process
• Besides a kernel and a shell, a key concept in
UNIX is that of a process.
• Every command that will be input by the user
creates a process in UNIX.
• It is possible that several processes exist
simultaneously in UNIX.
– Some created by the user, and some by UNIX itself.
• A process can be viewed as an object having one
input and two outputs:
– Standard input (stdin);
– Standard output (stdout);
– Error output (stderr).
Process

Process environment

Environment parameters
Output

Input

PROCESS

Error
report
Process
• A default standard input device is the keyboard
and default standard and error output device is
the monitor.
• It is possible to redirect them, i.e., input from and
output to different devices (such as a printer or a
file).
• It is possible to use buffers upon input and
output, i.e., to collect more lines that will be
received from the standard input at once and/or
passed to the standard output at once.
– The error output does not utilize buffers – should an
error emerge, it will be immediately displayed on the
device serving the error output.
Process
• The process environment represents a collection
of variables that the operating system transfers to
the process.
– E.g., the default folder, the terminal on which the user
is connected and so on.
• It is assumed that the process is created (born),
exists (lives) in its environment for a certain
period of time, and then disappears from the
system (dies).
• There are processes that have no contact with
the user and function in the background –
daemon processes.
– The user has no interaction or effect upon these
processes.
File System
• An example of a file system in UNIX:

tmp etc bin usr dev aa

include bin lib ab


dat1
dat2
xxx

• In UNIX some folders have predefined names.


File System
• / – the root folder;
• /dev – it contains all special files linked to the
input/output, i.e., the devices connected to the
system;
• /etc – from et cetera; message-of-the-day, the
application password file and other files that can
be accessed only by the super-user
(administrator) of the system;
• /bin – executable versions of the UNIX
commands are placed here;
• /tmp – contains temporary files; it is usually
purged once per day, so it should not be used to
permanently store important data;
File System
• /usr – user list;
– /usr/bin – executable files that belong to an
individual user;
– /usr/include – contains the libraries that are
included in the C programming language code,
through the #include directives;
– /usr/users – if the system is multi-user, the
tree of users is placed here.
• /aa and /aa/bb – user created folders;
the folder /aa/bb contains files dat1,
dat2 and xxx.
File System
• UNIX recognizes three types of files:
– Folders – store other types of files (they may store
other folders as well);
– Special files – they are placed in the system folders
and simulate input-output devices (such as
/dev/lp0);
– Regular files – all other files.
Program Execution
• The UNIX shell can be considered a
programming language.
– It contains variables, subroutines, control
structures etc.
– It processes interrupts, performs numerical and
string processing, reads from and writes to various
devices etc.
• It is possible that several processes get carried
out simultaneously, while one being in the
foreground, and the others in the background.
System Administration
• In UNIX, all users are equal, except one, the
super-user (i.e., the root user).
• This used has access to system resources, that
other users don’t have.
– For example, this user can access any file by any
user, can remove an arbitrary process etc.
• The super-user privilege is given to the
administrator of the system, that ensures safe
and continuous work of the authorized users
of the system.
System Administration
• Some of the operations of the administrator
are:
– System start up and shut down;
– Setting of the system time and date;
– Entering new users into the system (assigning
their user names, passwords and working groups);
– Periodical back-up of the system state;
– Ownership modification of a user or group of
users;
– Creating new file systems instead of already
existing ones, through mounting new file trees;
– Monitoring and improving the system
performances.
Documenting the System And
Instruction Manuals
• In UNIX, the manual files are usually placed in
/usr/man.
• The command man displays pages of the system
manual on the screen.
date(1) date(1)
Version 1.1
NAME
date - print and set the date
SYNOPSIS
date [yymmddhhmm[.ss]]
DESCRIPT ION
If no argument is given , the current date and time are
printed. If an argument is given the current date is
set. yy is the last two digits of the year ; the first
mm is the month number;......etc. ...........................
FILES
/usr/adm/wtmp to record time setting
SEE ALSO
utmp(5)
DIAGNOST IC
' No permission' if you aren't super-user.......etc........
....................................
$ mandate 1
User Session Control
• A UNIX user always initiates his/her session by
inputting his/her user name and password.
login: marko
password: xxxxx
$_

• The prompt sign is $ for regular users, and #


for the administrator.
User Session Control
• To leave the session, command logout (or exit,
in some systems) is used, or Ctrl+d.
• To modify the password, the command
passwd is used.
– The password is stored in /etc/passwd.
– It is encrypted and not even the administrator can
see it.
– If the user forgets his/her password, the
administrator can remove it, so that the user
would need to enter a new one.
UNIX Commands Basics
• The general form of a UNIX command is
command options expressions file_name
– The options modify the action of the command by
specifying the details of the processing of the
command and/or the output of the results of this
processing;
– The expressions are strings of characters
representing the input for a given command;
– The file_name is the name of the file that is
affected by the given command.
Examples of UNIX Commands
• Command ls:
ls
lists all files in the current folder.
ls -l /bin
gives a detailed listing of all files in the /bin folder.
ls -ld /bin
gives a listing of the /bin folder details.
Examples of UNIX Commands
• Command who:
who
lists all users currently connected to the system.
$ who
root tty00 Feb 14 09:45
boban tty02 Feb 14 09:50
goran tty08 Feb 14 10:05
marko tty09 Feb 14 11:00
$_

who am I
lists information about the current user.
$ who am I
marko tty09 Feb 14 11:00
$_
Examples of UNIX Commands
• Command date:
date
lists the current date and system time.

• Command cal:
cal 3 2016
lists the calendar for March 2016.
cal 2016
lists the calendar for the entire year 2016.
Multiple Commands in the Same
Line
• It is possible that multiple commands be
placed in the same line.
• In this case, the commands should be
delimited by a semicolon (;)
$ who am i ; date
marko tty09 Mar 23 11:00
Sun Mar 23 11:45 2015
$_
Regular Expressions in the
Statements
• Statements in UNIX can be specified to work upon groups
of files if they use filters based on regular expressions.
• Basic symbols:
– ? – universal character;
– * – universal syllable;
– [ ] – elective set; the symbol “-” inside the square brackets
denotes an interval from-to;
– ! – negation of the condition set inside the square brackets.
• In regular expressions, the symbol ordering is
alphanumerical (ASCII) and not numerical.
– [1-30] denotes [0123] or [0-3]
– [6-12] denotes “6 or - or 1 or 2”
Regular Expressions in the
Statements
$ ls
co.5 cow coward coy
hog hug huge part2.1
part2.2 tart2.3 thug
$_

$ ls co?
cow coy
$_ remove – removes a
file
$ rm ?o?
$ ls
co.5 coward hug huge
part2.1 part2.2 start2.3 thug
$_
Regular Expressions in the
Statements
$ ls
co.5 cow coward coy hog hug huge part2.1
part2.2 tart2.3 thug
$_

$ cp h* /tmp
$ cd /tmp
$ ls
hog hug huge copy – copy
$_ a file
change directory –
$ ls co[xyz]
coy change the current
$_ working directory

$ rm [cdeghr]o[gw]
$ ls
co.5 coward coy hug huge part2.1 part2.2 start2.3
thug
$_
Regular Expressions in the
Statements
$ ls
co.5 cow coward coy
hog hug huge part2.1
part2.2 tart2.3 thug
$_

$ ls *[1-5]
co.5 part2.1 part2.2 start2.3
$_
print – sends a file
to a printer
$ lpr [!chp]*
$_
File Information String
• The command ls -l gives detailed
information about all files in the folder.
$ ls –l
drwxrwxr-x 2 IVAN proj1 512 Feb 14 12:11 C
drwxr-xr-x 2 IVAN proj1 1024 Feb 14 10:10 doc
-rwx--x--x 1 IVAN proj1 520 Feb 14 10:11 test1
$_

• Every row of the list is a file information string.


File Information String
drwxrwxr-x 2 IVAN proj1 512 Feb 14 12:11 C

• d – if the file is a directory; l – if it is a link; - – if it is a regular


file
• File privilege substring of 9 characters from the set {r, w, x, -};
• With how many files the file is connected;
• Name of the owner of the file;
• Name of the group of owners of the file;
• The size of the file in bytes;
• The date of the last update of the file;
• The name of the file.
File Privilege Substring
• Length of 9 characters, i.e., 3 characters for
privileges of the user itself, the group the user
belongs to and other users.
• The privileges are:
– read: the user can read from the file or obtain the
content of the folder;
– write: the user can modify the content of the file or
create and delete files in the folder;
– execute: the user can execute the file or make the
folder the current working folder;
– -: if the corresponding privilege is not given.
Privilege Update
• It is done using command chmod.
• It is regulated using:
Which privileges
– String notation; are assigned using
this command?
chmod "rwxrw-r--" dat2
– Octal notation.
chmod 764 dat2
• Since "rwxrw-r--" is interpreted as binary
111110100, which is 764 octal.
Privilege Update
• Privileges may be defined (=), added (+) or
revoked (-) to the user-owner (u), the group
(g) or all other users (o):
$chmod u=rw go=r dat2
$chmod u=rwx g=r o=r dat3
$chmod go+w dat2

You might also like