2020.04.02 - UNIX Shell 1 - Lecture
2020.04.02 - UNIX Shell 1 - Lecture
2020.04.02 - UNIX Shell 1 - Lecture
UNIX Shell 1
Lecture
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:
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
$_