Review of: Chapters One - Four
2
History of Unix OS
The Unix OS was developed (based on Multics & CTSS operating systems) by Ken Thompson at the AT&T Bell Laboratories in 1969. He wanted to create an multi-user operating system to run “space wars” game.Ken’s philosophy was to create an operating system with commands or “utilities” that would do one thing well very well (i.e. UNIX).
3
History of Unix OS
The first versions of UNIX were written in “machine-dependent” program (such as PDP-7).Ken Thompson approached Dennis Ritchie developer of C program), and in 1973 they compiled UNIX in C programming language to make operating system “portable” to other computers systems.
4
History of Unix OS
The Unix OS is a multi-user OS allowing more that more person to directly communicate with the computer.Although the OS can only work on one task at a time, a small piece of time (time slice) is dedicated to each task or user - this is referred to as “time-sharing”.Time sharing gives the illusion that the CPU is giving all the users its full attention
5
History of LinuxLinux operating system developed by Finnish programming student named Linus Torvalds
Linus wanted to develop Unix-like OS just to experiment with the new 386 MHz personal computer
6
Introducing the UNIXOperating System
UNIX can be used on systems functioning as: Dedicated servers or client workstations
in a server-based network Client/server workstations connected to
a peer-to-peer network Stand-alone workstations not connected
to a network
7
Introducing the UNIXOperating System
UNIX is a multi-user system Allows many users access and share the
resources of a server computer
UNIX is a multitasking system Allows user to execute more than one program
at a time
UNIX is a portable operating system Used in many computing environments
8
UNIX Concepts
Shell The interface between user and OS
Hierarchical Structure Directory and subdirectory organization
Layered components Layers of software surround the computer’s
inner core
9
Linux and UNIX
Linux is UNIX-like Not written from traditional UNIX code
Linux is original code Includes POSIX standards
Other Linux information Created by Linus Torvalds Offers all the complexity of UNIX Linux can coexist with other OSs
10
Connecting to a UNIX System
Remotely through Telnet/Secure Shell
Through network client software
As peer on peer-to-peer network
On a stand-alone PC
Through a dumb terminal
11
Connecting to UNIX
Telnet terminal emulation software Easy and unsecure
Secure Shell Terminal emulation software Session encrypted end-to-end Bundled with secure ftp and copy
X-Windows
12
Logging in to UNIX
Log in by entering username and password when UNIX system booted or connected toEnter at prompt (command-line mode) or into login box (GUI mode)You’re at the Shell prompt -- Now commands can be issued at the command prompt
13
Your ShellShells interpret commands and act as first-class programming languages
A default shell is associated with your account when created – Bash is the default shell in Linux (cat /etc/shells)
A short list of some UNIX shells: Bourne (original Unix shell) Cshell (similar to C programming language) Korn (backwards-compatible upgd to
bourne) Bash (combo of Bourne, C and Korn shells)
14
Entering CommandsTo interact with UNIX, a command is entered at the command prompt
UNIX is case-sensitive and most commands are typed in lower case
Two categories of commands User-level: perform tasks System administration: system
management
15
Entering Commands
The date command Displays the system date, which the
system administrator maintains
The cal command Shows the system calendar
The who command Shows who is using the system and their
current location
16
Entering CommandsCommand-line editing Certain keystrokes perform command-
line editing (shell dependent)
Multiple command entry More than one command on one line
by separating with a semicolon(;)
The clear command Clears the current screen
17
Entering CommandsCommand-line history Use up and down arrow keys to
scroll through command history
The whatis command Displays a brief description of a
command for help purposes Note the numbers in ()’s – that is the
man section
18
Logging Out of UNIX
Logging out ends your current process and indicates to UNIX that you are finished
Logging out is shell dependent Bourne, Korn, Bash – exit or Ctrl-D C shell – logout command
19
Understanding the Role of the UNIX System Administrator
System administrator manages the UNIX system Adds users and deletes old accounts Called root (also called the superuser) Unlimited permission to alter system (in other
words very dangerous) Prompt ends with # (pound) symbol Normal user prompt $ (dollar) % (percent)
symbol
20
Changing PasswordsFor security purposes, changing passwords is necessary Use the passwd command UNIX allows new password if:
The new password differs by at least three characters It has six or more characters, including at least two
letters and one number It is different from the user name
passwd To change current user’s password passwd <username> To change specified
user
21
Viewing Files with cat, more, less, head, and tail Commands
Use cat, more, less and tail to view file contents: cat displays a whole file at one time more displays a file one screen at a time,
allowing scroll down less displays a file one screen at a time,
allowing scroll down and up tail displays the end of a file head displays the beginning of a file
22
Viewing Files with cat, more, less, head, and tail Commands
Use head and tail to view the first few or last few lines of a file head displays the first few lines tail displays the last few lines
23
Redirecting Output
The greater than sign (>) is called a redirection symbol
Create a new file or overwrite an existing file by attaching (>) to a command that produces output
To append to an existing file, use two redirection symbols (>>)
24
Understanding the UNIX File System
A file is the basic component for data storage UNIX considers everything it interacts with a file
A file system is UNIX’s way of organizing files on mass storage (disk) devices A physical file system is a section of the hard disk
that has been formatted to hold files
The file system is organized in a hierarchical structure similar to an inverted tree
25
26
Understanding the Standard Tree Structure
The structure starts at the root level Root is the name of the file at this basic level
and it is denoted by the slash character (/)
A directory is a file that can contain other files and directories
A subdirectory is a directory within a directory The subdirectory is considered the child of the
parent directory
27
Using UNIX Partitions
The section of the disk that holds a file system is called a partition
When installing UNIX, one of the first tasks is deciding how to partition a storage device, or hard disk
Hard disks may have many partitions
UNIX partitions are given names
Windows Linux SolarisC: (1st Drive, 1st Part) hda1 c0d0s0C: (1st Drive, 2st Part) hda2 c0d0s1
C: (2nd Drive, 1st Part)
hdb1 c0d1s0
28
Using UNIX Partitions
Storage devices are called peripheral devices
Peripheral devices connect to the computer through electronic interfaces IDE - Integrated Drive Electronics SCSI - Small Computer System Interface (sda1)
29
Exploring the Root File System
UNIX must mount a file system before any programs can access files on it
To mount a file system is to connect it to the directory tree structure
The root file system is mounted by the kernel when the system starts
30
The root directory contains sub-directories that contain files: /bin contains binaries, or executables
needed to start the system and perform system tasks
/boot contains files needed by the bootstrap loader as well as kernel images
/dev contains system device reference files
(Next slide is wrong. Should /dev)
Exploring the Root File System
31
32
Exploring the Root File System
Root subdirectories continued: /etc contains configuration files that the
system uses when the computer starts /lib contains kernel modules, security
information, and the shared library images
/mnt contains mount points for temporary mounts by the system administrator
/proc is a virtual file system allocated in memory only
33
Exploring the Root File System
Root subdirectories continued: /root is the home directory of the root
user, or the system administrator /sbin contains essential network
programs used only by the system administrator
/tmp is a temporary place to store data during processing cycles
/var contains subdirectories which have sizes that often change, such as error logs
34
Using the Mount Command
Users can access mounted file systems which they have permission (covered later) to access
Additional file systems can be mounted at any time using the mount command
To ensure system security, only the root user uses the mount command
35
Paths and Pathnames
To specify a file or directory, use its pathname, which follows the branches of the file system to the desired file A forward slash ( / ) separates each
directory name The UNIX command prompt may indicate
your location within the file system Use the UNIX pwd command to display
the current path name
36
Bash Prompt Syntax
Command Displays
PS1=“\t” 02:16:15
PS1=“\t\\” 02:16:30\
PS1="\\s-\\v\\\ $" bash-2.05b $
PS1=“[\u@\h \W]\$” [userid@host dir]$
To see your PS1 variable type and enter: echo $PS1
To read more look at the man page for bash man bash
37
Navigating the File System
To navigate the UNIX directory structure, use the cd (change directory) command
UNIX refers to a path as either: Absolute - begins at the root level and
lists all subdirectories to the destination file
Relative - begins at your current working directory and proceeds from there
38
Managing Directories and Filesmkdir (make directory) command Create a new directory
rmdir (make directory) command Delete an empty directory
cp (copy) command Copy files from one director to another
rm (remove) command Delete files
39
Setting File Permissions
40
Setting File Permissions
File Permissionsr Owner has read
w Owner has write
x Owner has execute
r Group has read
- Group does not have write
x Group has execute
r Others have read
- Others do not have write
x Others have execute
41
Setting File Permissions
chmod command To set file permissions Settings are read (r), write (w), execute
(x) The three types of users are owners,
groups, and others
Setting permissions to directories Use execute (x) to grant access
vi editor
Pronounced: `vee eye‘’
Guide to UNIX Using Linux, 2E
What is vi ?
The visual editor on the Unix.Before this the primary editor used on Unix was line editor User was able to see/edit only one line of the
text at a time
The vi editor is not a text formater you cannot set margins center headings Etc…
Guide to UNIX Using Linux, 2E
Characteristics of vi
The vi editor is a very powerful but at the same time it is crypticIt is hard to learn, specially for windows usersThe best way to learn vi commands is to use them
45
Vim equals Vi
The current iteration of vi for Linux is called vim Vi Improved http://www.vim.org
Guide to UNIX Using Linux, 2E
Starting vi
Type vi filename at the shell promptAfter pressing enter the command prompt disappears and you see tilde(~) characters on all the linesThese tilde characters indicate that the line is blank
Guide to UNIX Using Linux, 2E
Vi modesThere are two modes in vi Command mode Input mode
When you start vi by default it is in command modeHow can you go to command mode from input mode?By pressing the Esc key
Guide to UNIX Using Linux, 2E
How to exit from vi
First go to command mode press Esc There is no harm in
pressing Esc even if you are in command mode. Your terminal may just beep or flash if you press Esc in command mode
There are different ways to exit when you are in the command mode
Guide to UNIX Using Linux, 2E
How to exit from vi
:q <enter> is to exit, if you have not made any changes to the file:q! <enter> is the forced quit, it will discard the changes and quit:wq <enter> is for save and Exit:x <enter> is same as above commandZZ is for save and Exit (Note this command is uppercase)
50
You can move around only when you are in the command modeArrow keys usually works(but may not)The standard keys for moving cursor are: h - for left l - for right j - for down k - for up
Moving Around
51
w - to move one word forwardb - to move one word backward$ - takes you to the end of line<enter> takes the cursor the the beginning of next line
Moving Around
52
- - (minus) moves the cursor to the first character in the current lineH - takes the cursor to the beginning of the current screen(Home position)L - moves to the Lower last lineM - moves to the middle line on the current screen
Moving Around
53
f - (find) is used to move cursor to a particular character For example, fa moves the cursor from
the current position to next occurrence of ‘a’
F - finds in the reverse direction
Moving Around
54
) - moves cursor to the next sentence } - move the cursor to the beginning of next paragraph( - moves the cursor backward to the beginning of the current sentence { - moves the cursor backward to the beginning of the current paragraph% - moves the cursor to the matching parentheses
Moving Around
55
Control-d scrolls the screen down (half screen) Control-u scrolls the screen up (half screen)Control-f scrolls the screen forward (full screen)Contol-b scrolls the screen backward (full screen).
Moving Around
56
To enter the text in vi you should first switch to input mode To switch to input mode there are
several different commands a - Append mode places the insertion
point after the current character i - Insert mode places the insertion
point before the current character
Entering text
57
I - places the insertion point at the beginning of current line
o - is for open mode and places the insertion point after the current line
O - places the insertion point before the current line
R - starts the replace(overwrite) mode
Entering text
58
Editing text
x - deletes the current characterd - is the delete command but pressing only d will not delete nothing you need to press additional keysdw - deletes to end of worddd - deletes the current lined0 - deletes to beginning of lineThere are many more keys to be used with delete command
59
The change command
c - this command deletes the text specified and changes the vi to input mode. Once finished typing you should press <Esc> to go back to command modecw - Change to end of wordcc - Change the current lineThere are many more options
60
Structure of vi command
The vi commands can be used followed by a number such as n<command key(s)> For example dd deletes a line 5dd will
delete five lines.
This applies to almost all vi commands
61
Undo and repeat command
u - undo the changes made by editing commands. (dot or period) repeats the last edit command
62
Copy, cut and paste in vi
yy - (yank) copy current line to buffer nyy - Where n is number of linesp - Paste the yanked lines from buffer to the line belowP - Paste the yanked lines from buffer to the line above
(the paste commands will also work after the dd or ndd command)
63
UNIX Approach toFile Processing
Based on the approach that files should be treated as nothing more than character sequences
Because you can directly access each character, you can perform a range of editing tasks – this offers flexibility in terms of file manipulation
64
Understanding UNIX File Types
Regular files, also known as ordinary files Create information that you maintain and
manipulate, and include ASCII and binary files
Directories System files for maintaining file system structure
Special files Character special files relate to serial I/O devices
Communicates one character at a time Block special files relate to devices such as disks
Communicates using blocks of data
65
Using Input and Error RedirectionYou can use redirection operators to retrieve input from something other than the standard input device and send output to something other than the standard output device
Examples of redirection: Redirect the ls command output to a file, instead
of to the monitor (or screen) Redirect a program that receives input from the
keyboard to receive input from a file instead Redirect error messages to files, instead of to
the screen by default
66
Manipulating Files
When you manipulate files, you work with the files themselves, as well as their contentsCreate files using output redirection cat command - concatenate text via
output redirection touch command - used to create
empty files
67
Manipulating Files
Delete files when you no longer needed rm command - permanently removes a file or
an empty directory The -r option of the rm command will remove
a directory and everything it contains
Copy files as a means of back-up or as a means to assist with new file creation cp command - copies the file(s) specified by
the source path to the location specified by the destination path
68
Manipulating Files
Moving a file in order to change the directory that contains it mv command - removes file from one
directory and places it in another
Finding a file helps you locate it in the directory structure find command - searches for the file
that has the name you specify
69
Manipulating Files
Combining files using output redirection cat command - concatenate text of two
different files via output redirection paste command - joins text of different files
in side by side fashion
Extracting fields of a file using output redirection cut command - removes specific columns or
fields from a file
70
Manipulating Files
Re-arranging the contents of a file sort command - sorts a file’s contents
alphabetically or numerically The sort command offers many options:
You can sort the contents of a file and redirect the output to another file
Utilizing a sort key which provides the option of sorting on a field position within each line
71
Using Script Files
UNIX users create shell script files to contain commands that can be run sequentially as a set – this helps with the issues of command automation and re-use of command actions
UNIX users use the vi editor to create script files, then make the script executable using the chmod command with the x argument
72
Using the Join Command
The join command is used in relational database processingRelational databases consider files as tables and records as rowsRelational databases also consider fields as columns that can be joined to create new recordsThe UNIX join command lets you extract information from files sharing a common field
73
Chapter Summary
UNIX supports regular files, directories, and character and block special filesFile’s structures depend on data being stored and three kinds of regular files are unstructured ASCII characters, records and treesWhen running, UNIX receives input from the standard input device (keyboard) also known as stdin, and sends output to the standard output device (monitor) also known as stdout. Another standard device, stderr, refers to the error file that defaults to the monitor
74
Chapter Summary
The touch command updates a file’s time and date stamps and creates empty filesThe rmdir command removes empty directoriesThe cut command extracts specific columns or fields from a fileTo combine two or more files, use the paste commandUse the sort command to sort a file’s contents alphabetically or numerically
75
Chapter Summary
To automate command processing, include commands in a script file that you can later execute as a programUse the join command to extract data from two files sharing a common field and use this field to join the two filesAwk is a pattern-scanning and processing language useful for creating a formatted report with a professional look
76
Chapter Summary
Most shells provide basic command-line editing capabilities and keep a history of your most recently used commands
You can view the contents of files with view commands such as cat, less, more, head, and tails