Presentation2x

Download Report

Transcript Presentation2x

UNIX Introduction
What is an Operating System?
• The operating system (OS) is the program which starts up
when you turn on your computer and runs underneath all
other programs - without it nothing would happen at all.
• In simple terms, an operating system is a manager. It manages
all the available resources on a computer, from the CPU, to
memory, to hard disk accesses.
• Tasks the operating system must perform:
– Control Hardware - The operating system controls all the parts of the
computer and attempts to get everything working together.
– Run Applications - Another job the OS does is run application
software. This would include word processors, web browsers, games,
etc...
– Manage Data and Files - The OS makes it easy for you to organize your
computer. Through the OS you are able to do a number of things to
data, including copy, move, delete, and rename it. This makes it much
easier to find and organize what you have.
General Characteristics of UNIX as an
Operating System (OS)
•
•
•
•
•
•
Multi-user & Multi-tasking - most versions of UNIX are capable of allowing multiple
users to log onto the system, and have each run multiple tasks. This is standard for most
modern OSs.
Over 30 Years Old - UNIX is over 30 years old and it's popularity and use is still high.
Over these years, many variations have spawned off and many have died off, but most
modern UNIX systems can be traced back to the original versions. It has endured the
test of time. For reference, Windows at best is half as old (Windows 1.0 was released in
the mid 80s, but it was not stable or very complete until the 3.x family, which was
released in the early 90s).
Large Number of Applications – there are an enormous amount of applications
available for UNIX operating systems. They range from commercial applications such as
CAD, Maya, WordPerfect, to many free applications.
Free Applications and Even a Free Operating System - of all of the applications
available under UNIX, many of them are free. The compilers and interpreters that we
use in most of the programming courses here at UMBC can be downloaded free of
charge. Most of the development that we do in programming courses is done under the
Linux OS.
Less Resource Intensive - in general, most UNIX installations tend to be much less
demanding on system resources. In many cases, the old family computer that can
barely run Windows is more than sufficient to run the latest version of Linux.
Internet Development - Much of the backbone of the Internet is run by UNIX servers.
Many of the more general web servers run UNIX with the Apache web server - another
free application.
Advantages of Unix
•
•
•
•
•
•
•
•
Portable
Multi user
Multitasking
Networking – log into the any site
Organized file system
Device independence – i/o vs files
Utilities – > 100 utilities, productivity
Services – administrative tools built in
Flavors of UNIX
•
•
•
•
These can be grouped into two categories: Open Source and Proprietary
Proprietary: (redistribution and modification prohibited or restricted; not free)
– Solaris - Access to a Solaris UNIX server (solaris.gl.umbc.edu) via SSH access.
– IRIX - There are a couple of IRIX machines in the basement of the library, as
well as server access (irix.gl.umbc.edu) via SSH access.
– Mac OS X - no access currently available at UMBC.
– and many others...
Open Source: (source code is readily available and free to modify)
– FreeBSD - no access currently available at UMBC.
– Linux Distributions - access is available in the form of dual-boot PCs scattered
throughout the Engineering building. There are also several Linux servers
(linux.gl.umbc.edu) through which access is available.
• RedHat (used by UMBC) and the Fedora Project (maintained by RedHat)
• Mandrake
• Debian
• SuSE
• Slackware
• and many others...
As a side note, Linux is a open source UNIX-based OS that was originally developed
in 1991 by Linus Torvalds, a Finnish undergraduate student.
UNIX Interfaces
• There are 2 means of connecting to UNIX :
– You can be sitting in front of a dual-bootable PC that you
have booted into Linux and logged onto. All of your
commands are then being run locally on that computer.
When you logon in this manner you have a full GUI
environment.
– You can connect remotely to one of the UNIX servers
(whether from home or at the labs). This is often how your
projects are suggested to be developed as they are graded
on those same servers. When you logon in this manner
you have a command line (or text based) environment. You
can also open up a command line on local lab machines as
well.
Command Line Interface
• You also have access to some UNIX servers as well.
– You can logon from virtually any computer that has
internet access whether it be Windows, Mac, or UNIX
itself.
• In this case you are communicating through a local
terminal to one of these remote servers.
– All of the commands actually execute on the remote
server.
– It is also possible to open up graphical applications through
this window, but that requires a good bit more setup and
software. (Time permitting, we may cover how to do this.)
Graphical User Interfaces (GUIs)
• When you logon locally, you are presented with
graphical environment.
• You start at a graphical login screen. You must enter
your username and password. You also the have the
option to choose from a couple session types. Mainly
you have the choice between Gnome and KDE.
• Once you enter in your username and password, you
are then presented with a graphical environment
that looks like one of the following...
Programming Tools and Utilities Available
under Linux
• Text Editors
–
–
–
–
Xemacs
Emacs
Pico
vi
• Compilers
– C compiler - gcc
– C++ compiler - g++
– Java compiler & Java Virtual
Machine - javac & java
• Debuggers
– C / C++ debugger - gdb
• Interpreters
– Perl - perl
– Tcl/Tk - tcl & wish
• Miscellaneous
– Web Browsers - Mozilla,
Netscape, Firefox, and Lynx
(lynx is text based)
– Instant Messengers - Gaim
– Email - Netscape is there, but
we will learn Pine
Figure 1-6
Components of UNIX
11
Chapter 1 Unix (42 slides)
CTEC 110
Kernel
• Core or nucleus of an operating system
• Interacts with the hardware
• First program to get loaded when the system
starts and runs till the session gets terminated
• Different from BIOS which is hardware
dependent.
• Kernel is software dependent
Softsmith Infotech
Shell
•
•
•
•
Program that interacts with kernel
Bridge between kernel and the user
Command interpreter
User can type command and the command is
conveyed to the kernel and it will be executed
Softsmith Infotech
Types of Shell
•
•
•
•
•
•
Sh – simple shell
BASH – Bourne Again Shell
KSH – Korne Shell
CSH – C Shell
SSH – Secure Shell
To use a particular shell type the shell name at the command
prompt.
– Eg $csh – will switch the current shell to c shell
• To view the available shells in the system, type cat /etc/shells
at the command prompt
• To view the current shell that is being used, type echo $SHELL
at the command prompt
Softsmith Infotech
UNIX File System
• One of the remarkable features of the UNIX operating system
is the concept of files used in it.
• In UNIX a file is a sequence of bytes of data that reside in semi
permanent form on some stable medium.
• This file can contains anything you can represent as a stream
of bytes. So every thing including a network interface, a disk
drive, a keyboard, a printer is treated as a file.
• As a result, all input and output devices are treated as files in
UNIX, as described under file types and file system structure.
• File management in the UNIX system is
extremely flexible and powerful.
• It provides a hierarchical directory scheme.
• A directory is a container for a group of files
and directories, directories can be included in
other directories.
• For example dir1/goodbye refers to the file
goodbye in the directory dir1.
Files and directories
• A file is a sequence of bytes of data that
resides on medium such as (disk..).
• Text file are a simple example of this structure,
there is an ASCII character called newline is
used to delimit lines, which create a logical
text structure on a file.
Types of Files
•
•
•
Simple/ordinary file, used to store info and data on
secondary storage device, typically a disk.
It can contain a source program, an executable program such
as compilers, DB tools, pictures, audio, graphics, and so on.
Unix does not treat any kind of these files differently from
others. For example a C++ file is no different to UNIX than an
HTML file, however the files are treated differently by C++
compiler and WEB browser.
Types of Files (cont…)
• File names are limited to 14 chars in system V and 255 chars in BSD.
• To avoid any problem use only letters, numbers, period and underscore.
• Extensions have no meaning to UNIX, they are parts of files names, used
by users to mark their files types.
• The following are the common files extensions:
.bmp bit-mapped picture file.
.c
c source code.
.C, .cpp
c++ source code
.gif
graphics/picture file.
.html file for a web page.
.o
object file
.ps
post script code
.z
compressed file
Types of Files (cont…)
• Directory files, directory file contains the name of other files
and/or directories (sub directory).
• Directories have names just like other files, and these names
obey the same naming rules as normal files.
• A directory is a place within the file system as a whole that
contains files. This is analogous to a file drawer in your desk,
where you can put things. You can construct filenames that
include a directory as part of the name. The slash ‘/’ char is
used to separate the different components of a file name of
this form.
Types of Files (cont…)
• A directory is used to store a record for each
file or subdirectory it contains.
• This record (also called directory entry)
consists of the file inode number and the file
name.
• inode (index node) is a 4 byte number and is
an index for an array on the disk.
• An element of this array contains file
attributes such as file size.
Types of Files (cont…)
• Link files, the link file points to the existing file, allowing you
to rename an existing file and share it without duplicating its
contents.
• A link is a way to establish connection between the file to be
shared and the directory entries of the user who want to
access the file. To establish that link you need to set up an
appropriate permission to the file then issue the ln command
to link the file to a directory. There is more in chapter 11
about link files.
Types of Files (cont…)
• Special files (devices), it is a mean of accessing hardware
device, including the keyboard, hard disk, CD-ROM drive…etc.
• Each hardware device is associated with at least one special
file.
• A command or an application accesses the special file in order
to access the corresponding device.
• There are two types: a character special file for a char
oriented devices such as for keyboard and block special file
for block oriented devices such as a disk.
• Usually they reside in the /dev directory.
File System Structure
• The UNIX file system is structured hierarchically upside
down treelike, so it start with root directory and can have
any number of files or sub directories under it. A typical
UNIX system contains hundreds of files and directories,
organized as the following
root
bin
sh
tmp
ps
etc
passwd
user
Proj a
Proj b
Standard Directories and Files
• Root directory (/), at the top of the file system hierarchy and denote
as a slash (/), it is the master cabinet which contains all. Try
command $ls /.
• /bin it is known as binary directory, it contains binary -executablesimages of most UNIX commands, including cat, kill, mv, rm, echo,
date, mkdir, ksh, pwd...etc. all file in this directory either executable
files or symbolic link to executables files. Usually it is a symbolic link
to /usr/bin directory.
• /dev it is the device directory, contains files corresponding to the
devices (terminals, disk drives..) connected to the computer. These
are the special files mentioned earlier. Some files like lp (line
printer), hd (hard drive), tty (terminal) are example of these files.
Standard Directories and Files (cont…)
• /etc, contains commands and files for system administration. A
typical user not allowed to use these files and commands. Files in
this directory include login, passwd, and profile.
• /lib, contains a collection of related files for a given language in a
single file called an archive. Atypical UNIX system contains libraries
for C, C++ and other languages. The archive file is used by
application developed by that language. Some libraries are also
stored in /usr/lib directory.
• /lost+found, it contains all the files not connected to any directory.
These files are found by a UNIX tool, fsck (file system check).
Standard Directories and Files (cont…)
• /tmp, it contains temporary files, all files are deleted periodically so
the disk does not get filled with temp files. The life of this is set by
system administrator.
• /users, normally hold the home directories of all users of the
system. It may be located in many various part of the file system
structure.
• /usr, it may hold some directories which contains the UNIX utilities,
tools, languages, libraries, and manual pages. Two of the most
important sub directories in this directory are /bin and /lib.
• /var, it contains among several other directories, the
/var/spool/mail directory that receive and holds your incoming mail
messages, when you read your mail, it comes from a file in this
directory, once you have read the mail, it is put in a file in your
home directory called mbox.
Standard Directories and Files (cont…)
• /etc/passwd, contains one line for every user on the system and describes
that following
– user login name, user name known to the system and type.
– password, encrypted version of the password.
– user-id, integer between 0 and 65535 assigned to the user, 0 is for
super user, 1 through 99 are reserved
– group id, identify the group the user belong to and also is an integer
from 0 to 65535.
– user info, typically the user full name.
– home directory, absolute path for the user home.
– login shell, absolute path for the user login shell.
Pathnames
The pathname of a file includes the file
name and the name of the directory that
holds the file, and the name of the
directory that holds the directory that holds
the file, and the name of the … up to the
root
The pathname of every file in a given
filesystem is unique.
Pathnames (cont.)
To create a pathname you start at the root
(so you start with "/"), then follow the path
down the hierarchy (including each
directory name) and you end with the
filename.
In between every directory name you put a
"/".
Pathname Examples
/
bin/
etc/
Hollid2/
netprog
home/
tmp/
scully/
unix/
X
usr/
bin/ local/
ls
Syllabus
/home/hollid2/unix/Syllabus
who
/usr/bin/ls
Absolute Pathnames
The pathnames described in the previous
slides start at the root.
These pathnames are called "absolute
pathnames“.
Relative Pathnames
Prefixed w/the current directory, $PWD
So, relative to the current working directory
$ cd /home/hollid2
$ pwd
/home/hollid2
$ ls unix/Syllabus
unix/Syllabus
$ ls X
ls: X: No such file or directory
$ ls /home/scully/X
/home/scully/X
Special Relative paths…
. – The current directory
.. – The parent directory
$ pwd
/home/holid2
$ ls ./netprog
./netprog
$ ls ../scully
X
Command Format
• Format: command name and 0 or more
arguments:
% commandname [arg1] ... [argN]
• By % sign I mean prompt here and hereafter.
• Arguments can be
– options (switches to the command to indicate a
mode of operation) ; usually prefixed with a
hyphen (-)
– non-options, or operands, basically the data to
work with (actual data, or a file name)
July 10, 2003
Serguei A. Mokhov,
[email protected]
35
Command Grouping
• Semicolon: “;”
• Often grouping acts as if it were a single
command, so an output of different
commands can be redirected to a file:
• % (date; cal; date) > out.txt
July 10, 2003
Serguei A. Mokhov,
[email protected]
36
Redirection and Pipes
• Redirection
– Input redirection
• wc < file1 – Content of file 1 is given as input for wc command that
counts the no of lines, words and characters in a file
– Output redirection
• cat file > newfile – Copies file’s content to newfile. Over writes the
existing content
• cat file >> newfile – Appends the new content to the existing
content
• Pipes
– Output of first command is input for the second and so on
– who | wc –l – Number of lines in the output of who command will be
displayed
Softsmith Infotech
mkdir
• Creates a directory.
• % mkdir newdir
• Often people make an alias of md for it.
July 10, 2003
Serguei A. Mokhov,
[email protected]
38
cd
• Changes your current directory to a new one.
• % cd /some/other/dir
– Absolute path
• % cd subdir
– Assuming subdir is in the current directory.
• % cd
– Returns you to your home directory.
July 10, 2003
Serguei A. Mokhov,
[email protected]
39
pwd
• Displays personal working directory, i.e. your
current directory.
• % pwd
July 10, 2003
Serguei A. Mokhov,
[email protected]
40
rmdir
• Removes a directory.
• % rmdir dirname
• Equivalent:
– % rm -r dirname
July 10, 2003
Serguei A. Mokhov,
[email protected]
41
ls
• % ls -F
• List directory contents
• Has whole bunch of
options, see man ls for
details.
• % ls
– append “/” to dirs and “*” to
executables
• % ls -l
– long format
– all files except those starting
with a “.”
• % ls -a
– all
• % ls -A
– all without “.” and “..”
July 10, 2003
• % ls -al
• % ls -lt
– sort by modification time
(latest - earliest)
• % ls -ltr
– reverse
Serguei A. Mokhov,
[email protected]
42
cat
• Display and concatenate files.
• % cat
– Will read from STDIN and print to STDOT every line you enter.
• % cat file1 [file2] ...
– Will concatenate all files in one and print them to STDOUT
• % cat > filename
– Will take whatever you type from STDIN and will put it into the file
filename
• To exit cat or cat > filename type Ctrl+D to indicate
EOF (End of File).
July 10, 2003
Serguei A. Mokhov,
[email protected]
43
more / less
• Pagers to display contents of large files page
by page or scroll line by line up and down.
• Have a lot of viewing options and search
capability.
• Interactive. To exit: ‘q’
July 10, 2003
Serguei A. Mokhov,
[email protected]
44
less
• less ("less is more") a bit more smart than the more
command
• to display contents of a file:
– % less filename
• To display line numbers:
– % less -N filename
• To display a prompt:
– % less -P"Press 'q' to quit" filename
• Combine the two:
– % less -NP"Blah-blah-blah" filename
• For more information:
– % man less
July 10, 2003
Serguei A. Mokhov,
[email protected]
45
touch
• By touching a file you either create it if it did
not exists (with 0 length).
• Or you update it’s last modification and access
times.
• There are options to override the default
behavior.
• % touch file
• % man touch
July 10, 2003
Serguei A. Mokhov,
[email protected]
46
cp
•
•
•
•
•
Copies files / directories.
% cp [options] <source> <destination>
% cp file1 file2
% cp file1 [file2] … /directory
Useful option: -i to prevent overwriting existing files
and prompt the user to confirm.
• -R option is used to copy entire directory structure
• Co –R dir1 Dir2
July 10, 2003
Serguei A. Mokhov,
[email protected]
47
mv
• Moves or renames files/directories.
• % mv <source> <destination>
– The <source> gets removed
• % mv file1 dir/
• % mv file1 file2
– rename
• % mv file1 file2 dir/
• % mv dir1 dir2
July 10, 2003
Serguei A. Mokhov,
[email protected]
48
rm
• Removes file(s) and/or directories.
•
•
•
•
% rm file1 [file2] ...
% rm -r dir1 [dir2] ...
% rm -r file1 dir1 dir2 file4 ...
%rm *- removes all files in a
directory
• %rm –r or –R- recursive deletion
• %rm –i –interactive deletion
• %rm –f Force removal
July 10, 2003
Serguei A. Mokhov,
[email protected]
49
script
• Writes a log (a typescript) of whatever happened in
the terminal to a file.
• % script [file]
• % script
– all log is saved into a file named typescript
• % script file
– all log is saved into a file named file
• To exit logging, type:
– % exit
July 10, 2003
Serguei A. Mokhov,
[email protected]
50