2. What Is an Operating System?
• Interface between Users and the Hardware
• Take care of Storage Management
• Take care of I/O device management
3. History of the UNIX Operating System
1969 AT&T Bell Labs UNICS system -designed by Ken
Thompson & Dennis Ritchie
1970 UNICS finally became UNIX
1973 UNIX rewritten in C, making it portable to different hardware
Mid 1970s University of California at Berkeley (BSD) contributed many
important features like vi, C shell etc.
1982 AT & T came back and started commercial production-
Editions ->Systems
Late 1980s AT & T released SVR4 unification of SV3.2,BSD,SunOs &
XENIX
1991 Linux from Linus Torvalds
1990s POSIX Standard, MIT introduced X-Windows
3
5. More Features of UNIX
• Hierarchical file system
• Multi tasking
• Multi user
• Pattern matching (wildcard characters)
• Programming facility
• Documentation
5
6. Command Line Format
Syntax:
$ command [-options] [arguments]
1. Separation
2. Order
3. Multiple options
4. Multiple arguments
6
7. Basic Commands(1)
ls list files and directories
ls -a list all files and directories
mkdir make a directory
cd directory change to named directory
cd change to home-directory
cd ~ change to home-directory
cd .. change to parent directory
pwd display current dir path
useradd add new user in the system
usermod modify user
userdel delete user
groupadd add new group in the system
8. Basic Commands(2)
cp file1 file2 copy file1 and call it file2
mv file1 file2 move or rename file1 to file2
rm file remove a file
rmdir directory remove a directory
cat file display a file
more file display a file a page at a time
who list users currently logged in
lpr -Pprinter psfile print postscript file to named printer
* match any number of characters
? match one character
man command read the online manual page for a
command
9. Basic Commands(3)
command > file redirect standard output to a file
command >> file append standard output to a file
command < file redirect standard input from a file
grep 'keyword' file search a file for keywords
% grep science science.txt
wc file count number of lines/words/characters in file
% wc -w science.txt
sort sort data (numerically or alphabetically)
Ex:
to sort the list of object, type
% sort < biglist
and the sorted list will be output to the screen.
10. The File System Hierarchy
/
usr etc home dev var tmp
bin sbin dsk rdsk adm sadm
ls who
10
11. File Path name
A sequence of file names, separated by slashes (/), that
describes the path, the system must follow to locate a
file in the file system
Absolute pathname (start from the /-directory):
Eg: /export/home/user1/file1
Relative pathname (start from the current directory)
./test1 (. = current directory)
../team03/.profile (.. = parent directory)
11
12. File Characteristics
$ ls -l
-rw-r--r-- 1 user3 class 37 Jul 24 11:06 f1
-rwxr-xr-x 1 user3 class 52 Jul 24 11:08 f2
drwxr-xr-x 2 user3 class 1024 Jul 24 12:03 memo
File Links Group Name
Type Timestamp
Owner Size
Permissions
12
13. Who can access a File?
The UNIX system incorporates a three-tier structure to define who
has access to each file and directory:
user The owner of the file
group A group that may have access to the file
other Everyone else
• The ls -l command displays the owner and group who has
access to the file.
$ ls -l
-rw-r--r-- 1 user3 class 37 Jul 24 11:06 f1
-rwxr-xr-x 1 user3 class 37 Jul 24 11:08 f2
drwxr-xr-x 2 user3 class 1024 Jul 24 12:03 memo
| |
owner group
13
14. File system security (access rights)
-rwxrwxrwx a file that everyone can read, write and execute
(and delete).
-rw------- a file that only the owner can read and write - no-
one else can read or write and no-one has
execution rights (e.g. your mailbox file).
16. chmod [options] file change access rights for named file
For example, to remove read write and execute permissions on the file
biglist for the group and others, type
% chmod go-rwx biglist
This will leave the other permissions unaffected.
To give read and write permissions on the file biglist to all,
% chmod a+rw biglist
17. Default Permissions
The default protections for newly created files and directories
are:
File -rw-r—r-- 644
Directory drwxr-xr-x 755
These default settings may be modified by changing the umask
value.
17
18. umask - Permission Mask
Umask specifies what permission bits will be set on a new
file or directory when created.
New Directory: 777 – 022 755 rwxr-xr-x
New File : 666 – 022 644 rw-r—r—
The default value of umask is set in /etc/profile. This can be
changed for all the users or a particular user
18
19. chown - Change File Ownership
Syntax:
chown owner [:group] filename ...
Changes owner of a
file(s) and, optionally, the
Example: group ID
$ id
uid=101 (user1), gid=101 (group1)
$ cp f1 /tmp/user2/f1
$ ls -l /tmp/user2/f1
-rw-r----- 1 user1 group1 3967 Jan 24 13:13 f1
$ chown user2 /tmp/user2/f1
$ ls -l /tmp/user2/f1
-rw-r----- 1 user2 class 3967 Jan 24 13:13 f1
Only the owner of a file (or root) can change the ownership of the file.
19
20. The chgrp Command
Syntax:
chgrp newgroup filename ...
Example:
$ id
uid=303 (user3), gid=300 (class)
$ ls -l f3
-rw-r----- 1 user3 class 3967 Jan 24 13:13 f3
$ chgrp class2 f3
$ ls -l f3
-rw-r----- 1 user3 class2 3967 Jan 24 13:13 f3
$ chown user2 f3
$ ls -l f3
-rw-r----- 1 user2 class2 3967 Jan 24 13:13 f3 20
21. su - Switch User Id
Syntax:
su [user_name]
Change your effective user ID and group ID
Example:
$ ls -l f1
-rwxr-x--- 1 user1 group1 3967 Jan 24 23:13 class_setup
$ id
uid=303 (user1), gid=300 (group1)
$ su – user2
Password:
$ id
uid=400 (user2), gid=300 (group1)
21
22. Special File Permissions – setuid, setgid,
sticky bit
setuid – changes the effective user id of the user to the owner of
the program
chmod u+s f1 or
– chmod 4744 f1
setgid – changes the effective group id of the user to the group
of the program
chmod g+s f1 or
chmod 2744 f1
sticky bit – ensures the deletion of files by only file owner in a
public writable directory
chmod +t f1 or
Chmod 1744 f1
22
23. What Is vi?
• A screen-oriented text editor
• Included with most UNIX system distributions
• Command driven
• Categories of commands include
– General administration
– Cursor movement
– Insert text
– Delete text
– Paste text
– Modify text
23
24. Starting and Ending a vi
Session
vi [filename] Start a vi edit session of file
Example:
$ vi testfile
- If the file doesn’t exist, it will be created
- Otherwise vi will open the existing file
All modifications are made to the copy of the file brought into
memory.
:wq or :x or <shift-zz> write and quit
:w write
:q quit
:q! Quit without saving
24
25. Cursor Control Commands
1G
<ctrl-b>
H
k
<up-arrow>
0 $
b,B w,W
h l
<left-arrow> <right-arrow>
<down-arrow>
j
L
<ctrl-f>
G
25
26. Input Mode: i, a, O, o
i will insert character at the present cursor position
I will insert character at the beginning of the line
a will append character at the present cursor position
A will append character at the end of the line
o will insert a blank line below
O will insert a blank line above
26
27. Deleting Text: x, dw, dd, dG
x deletes the current character
dw deletes the current word
dd deletes the current line
dG delete all lines to end of file, including current line.
With any of these you can prefix a number
Example: 3dd will delete 3 lines
d$ to delete to the end of the line
d0 to delete to the start of the line
27
28. Copying, moving and
changing Text
yy copy the line
yw copy the word p will paste the yanked lines below
dw cut the word P will paste the yanked lines above
dd cut the line
r will overwrite the current character
R will replace all text on the right of the cursor position
cw will replace only the current word
28
29. Searching for Text: /, n, N
/director will locate for the first occurrence of the
pattern ‘director’
n to locate the next occurrence
N to locate the previous occurence
29
30. Monitoring Process
The ps command dislays process status information
$ ps -f
UID PID PPID ... TTY ... COMMAND
john 202 1 ... tty0 ... -ksh
john 204 202 ... tty0 ... ksh
john 210 204 ... yyu0 ... ls -R /
john 212 204 ... tty0 ... ps -f
30
31. Shell Scripting
Shell scripting skills have many applications, including:
Ability to automate tasks, such as
Backups
Administration tasks
Periodic operations on a database via cron
Any repetitive operations on files
Increase your general knowledge of UNIX
Use of environment
Use of UNIX utilities
Use of features such as pipes and I/O redirection
32. Examples of Shell Scripting
Store the following in a file named simple.sh and execute it
#!/bin/sh
# Show some useful info at the start of the day
date
echo Good morning $USER
cal
last | head -6
Shows current date, calendar, and a six of previous logins
Notice that the commands themselves are not displayed, only
the results
Shell is a Command Intrepreter www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
Hierarchical File System Information is stored on the disk in containers known as files. Every file is assigned a name, and user accesses a file by referencing its name. Files normally contain data, text, programs, and so on. In the UNIX system, a directory can be used to store files or other directories. Multi-tasking In the Unix system several tasks can be performed at the same time. From a single terminal, a single user can execute several programs that all seem to be running simultaneously. Programming facility The UNIX shell is also a programming language; it was designed for a programmer, not casual end user. It has all the necessary ingredients like control structures, loops and variables that establish it as a powerful programming language on its own right. These features are used to design shell scripts- programs that also include UNIX commands in their syntax. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
A file has several characteristics associated with it. They can be displayed using the ls –l command. Type regular file or special file. Permission or mode access definition for the file. Links number of file names associated with a single collection of data. Owner user identification of file owner Group group identification for file access Size number of bytes file contains Timestamp date file last modified Name maximum of 14 characters www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
Who Has Access The three classes of users are: • Owner — Usually the person who created the file. • Group — Several users that have been grouped together by the system administrator. For example, the members of a department might belong to the same group. • Other — All other users on the system. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
You should also be aware of the default permissions assigned to all of your files and directories at the time you create them. You can list or change the default permission settings by using the umask command. Default file permissions are assigned by the system whenever you create a new file or directory, and these are governed by your umask setting. To restrict these default permissions for newly-created files and directories, use the umask command. When a new file is created, each bit in the file mode creation mask that is set causes the corresponding permission bit in the file mode to be cleared (disabled); hence the term mask. Conversely, bits that are cleared in the mask allow the corresponding file mode bits to be enabled in newly created files. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
setuid: When set-user identification (setuid) permission is set on anexecutable file, a user or process that runs this executable file is granted access based on the owner of the file (usually root) instead of the user who started the executable. For eg. the executable file /usr/bin/passwd is set with setuid so that when any nonprivileged user runs the command the effective user id is not of the user but that of root. Because of that the password is updated in the file /etc/shadow though the normal user dont have any write permission on this file. -r-sr-xr-x 1 root sys 17156 Jan 5 17:03 /usr/bin/su setgid: The set-group identification (setgid) permission is similar to setuid,except that the effective group ID of the user or the process is changed to the group owner of the file. Also, access is granted based on the permissions assigned to that group. For example, the mail program has a setgid permission used to read mail, or send mail to other users. -r-x--s--x 1 root mail 61288 Jan 5 16:57 /usr/bin/mail The setgid permission is a useful feature for creating shared directories. When a setgid permission is applied to a directory, files created in the directory belong to the group to which the directory belongs. Sticky Bit: If the directory has the Sticky Bit set, a file can be deleted only by the owner of the file, the owner of the directory, or by root. This prevents a user from deleting other users’ files from publicly writable directories. For example: # ls -ld /tmp drwxrwxrwt 6 root sys 719 May 31 03:30 /tmp www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
The vi editor is a powerful, versatile editing tool. The vi editor is included with every versions of UNIX. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
l or -> will move the cursor right by one character h or <- will move the cursor left by one character j or down arrow will move the cursor one line down k or up arrow will move the cursor up by one line up w or W will move cursor to the next word b or B will move cursor to the previous word 0 will move cursor to the beginning of the line $ will move cursor to the end of the line 1G will move cursor to the first line of the file G will move cursor to the last line of the file <ctrl-f> will move cursor down by a page <ctrl-b> will move cursor up by a page H will move cursor to the top of the current page M will move cursor to the Middle of the current page L will move cursor to the bottom of the current page www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
PID: Process ID PPID: Parent Process ID UID: User ID ps command will only show the processes started by the current user. ps -af will display all the processes started by all users ps -ef will display all the processes including the system processed www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar