Sie sind auf Seite 1von 48

UNIX OPERATING SYSTEM

- Ravi
www.etraining.guru

What is an Operating System ?


Definition: An Operating system (OS) is a collection of softwares
that manages computer hardware resources and provides
common services for computer programs. (as per Wikipedia!)

Circular View

Horizontal View

A simple definition - An Operating System is an interface between Hardware and User.

Examples of Operating Systems


DOS - Disk Operating System, a product of IBM. Not very user friendly!
Windows - A product of Microsoft. User friendliness through GUI
MacOS - Macintosh, a product of Apple. User friendliness through GUI

Unix - Originally CUI, now has GUI as well


Linux - Supports both CUI & GUI
If Windows is an OS, what are Windows 95, 98, ME, NT, 2000, XP, 7, and 8?

Similarly, Unix and Linux OSs have various flavors/versions too. Lets first look at Unix Evolution

Unix Evolution

MULTIcs
(MULTIplexed Information and Computing Service)

UNIX
By, Dennis Ritchie, Brain kernighan and Ken Thompson @AT&T Bell
Laboratories in early 1970's

Unix Evolution

Is the name of the family of operating systems


developed at Bell Laboratories around 1969.

Was largely the creation of two programmers working


at Bell Laboratories, Ken Thompson and Brain
Kernighan.

Was initially used in academic environments and


spread quickly to commercial environments also

Has got 90% of it developed in C language and, 10%


machine specific assembly code.

Basic UNIX system occupies around 10 MB disk space


on PCs.

Unix Evolution

Note: You can also call these Single Unix Specifications as POSIX - Portable Operating System Interface for UNIX

Unix Evolution

Open source (vs) Closed Source (vs) Mixed source?

Unix Evolution

Unix Evolution

What is LINUX?
Linux is a Unix clone written from scratch by Linus Torvalds with
assistance from a loosely-knit team of hackers across the Net. It
aims towards POSIX compliance.
Below are few popular Linux distributions:
Debian - A non-commercial distribution maintained by a volunteer developer community with a
strong commitment to free s/w principles
Ubuntu

- A popular desktop and server distribution derived from Debian

Fedora

- A community distribution sponsored by American company Red Hat

openSUSE

- A community distribution mainly sponsored by American company Novell

Mageia, Mint Linux, slackware, etc

Unix/Linux Main Features


Multitasking Capabilities
Multi-User Capabilities
Hierarchical Directory Structure
Security
Portability

UNIX Architecture

H/W
Shell

Tools &
Applications

Kernel

UNIX Architecture
Categorized as three levels:
Kernel - Core/Heart of the Operating System
Shell - User interface with Operating System
Tools and Applications - Utilities and User Programs

Note: In detail, will be covered in later sections

UNIX Server < --- > Terminals

Dumb Terminals / Nodes

Working in Unix Environment

Few things to remember


Working in Unix is majorly through commands
Syntax: command option(s) filename(s)
You must type spaces between commands, options, and filenames

Unix is case sensitive


Unix has a lot of commands! Dont try to byheart all of them

uname
Command Name: uname
Description: Print system information
Syntax: uname [option]
Usage:
uname -a
uname -s
uname -n
uname -r
uname -o
uname -son
uname -m
uname -i

==> Print all information


==> Kernal name
==> node name
==> Kernal release
==> operating system
==> Kernal name + os + node name
==> m/c hardware name
==> Hardware platform

man
Command Name: man
Description: Online manual pages; In built google!
Syntax: man [command]
Usage:
man uname
man man

==> to display uname manual pages


==> to display man manual pages

Note: In manual pages, q is to quit/come back to command prompt.


Space Bar is to scroll to next page

User Related
who Shows who is logged on
w Shows who is logged on and what they are doing
whoami Effective userid
who am i details about the userid

PS: man k who searches for word who in all man


pages

Unix MISC commands

tty Displays the terminal id

stty a
Example: stty intr ^a (To use CTRL + a for interrupt)

ifconfig To get IP address

Example: /sbin/ifconfig | grep 'inet addr:'| grep -v


'127.0.0.1' | cut -d: -f2 | awk '{ print $1}

Unix MISC Commands

cal

banner

clear

alias

Date Command

Gets/sets the date and time in the UNIX server


machine

Some Options : %D, %T, %A, %B, %H, %d

Examples
-

$ date

$ date +%D

$ date +%T

$ date +%d-%m-%Y

Date command contd


Setting system time: (Needs root permission)

Example:

$date MMDDhhmmYYYY.ss

Where, MM month
DD day
YYYY year
hh hour is based on 24 hour
mm minutes
ss seconds

Before we move on to next concept

uname
man
who
w
whoami
who am i
tty
ifconfig
cal
banner
stty
date
clear
alias

UNIX FILE SYSTEM

What is a filesystem?
A filesystem is a logical collection of files on a partition or disk. You can view
filesystems using df (or) bdf commands
Unix uses a hierarchical file system structure, much like an upside-down tree, with
root (/) at the base of the file system and all other directories spreading from there.
In Unix everything is a file - a stream of bytes. Unix treats documents, directories,
hard-drives, CD-Roms, modems, keyboards, printers, monitors, terminals, etc as
files.
For each file in the filesystem, UNIX stores administrative information in a
structure known as Inode (Index node).
ls -I /etc/passwd
stat /etc/passwd

Unix File system (tree) Structure

UNIX File System


3 types of files
Ordinary - Under user control (Ex: Notepad/wordpad in windows)
Directory - to hold list of files (like a folder in windows)

Speical - For example, device drivers, raw devices, etc

File System Commands

pwd

ls

cd

mkdir

touch

Print Working Directory

ls List directory contents


Syntax: ls [OPTIONS] [FILE(s)]
Examples: ls l

Long Listing

ls la

to list hidden files

ls ltr

To list files based upon modified time

ls l /home/cdctrg32/ravi/copyme (listing other user files)


Note: . is Current working directory, .. is Parent working directory

cd Change Directory
syntax: cd [options] [directory]
Example: To go to root directory, cd /
cd .

(You will be in pwd)

cd ..

(One directory up)

cd -

(Changes to previous working directory)

cd Enter (Changes to Home directory)

mkdir create directories


Syntax: mkdir [OPTIONS] [Directories]
Example: cd Enter (You will be placed in your home directory)
mkdir training

(Creates a new training directory)

ls l training

(View recently created directory)

cd training (Now you will be placed in training directory)


pwd; ls

(Bingo!!! No files created yet)

cp copy files and directories


Syntax: cp [OPTIONS] [SOURCE] [DEST]
Example:

cd training;

cp /home/cdctrg32/ravi/copyme mycopy (file copy)


cp R /home/cdctrg32/ravi/copy_dir . (directory copy)

mv move/rename files
Syntax: mv [OPTIONS] SOURCE DEST
Example: cd training
mv mycopy mvcopy

ln links b/w files


Syntax: ln [OPTION] target dest
Example: cd training
ln /home/cdctrg32/ravi/linkme linkme
ls l linkme
-rw-rw-r--

2 cdctrg32 cdctrg32

49 Jul 21 22:49 linkme

Note: type cat linkme. The usage of cat will be covered in later
sessions

File Permissions
ls l filename will display as below:
-rw-rw-r--

1 cdctrg32 cdctrg32

17 Jul 21 22:55 filename

Field 1: a set of ten permission flags.


Field 2: link count (don't worry about this)
Field 3: owner of the file
Field 4: associated group for the file
Field 5: size in bytes
Field 6-8: date of last modification (format varies, but always 3
fields)
Field 9: name of file

Field 1: Contains 10 characters


1 - directory flag, 'd' if a directory, '-' if a normal file, something else
occasionally may appear here for special devices.
2,3,4 - read, write, execute permission for User (Owner) of file
5,6,7 - read, write, execute permission for Group
8,9,10 - read, write, execute permission for Other

Permissions are set according to numbers. Read is 4. Write is 2.


Execute is 1. The sums of these numbers give combinations of
these permissions:

0 = no permissions whatsoever; this person cannot read,


write, orexecute the file
1 = execute only
2 = write only
3 = write and execute (1+2)
4 = read only
5 = read and execute (4+1)
6 = read and write (4+2)
7 = read and write and execute (4+2+1)

The below file has 664 permissions


-rw-rw-r--

1 cdctrg32 cdctrg32

17 Jul 21 22:55 filename

To give write permission to other group users,


chmod 666 filename
To take out permission from all other users: chmod 600 filename
Note: id command tells the default group id

Example: Can you cat the below file to see the contents of the file
cat /home/cdctrg32/ravi/passwords
Nope. But why?

chgrp & chown


chgrp NewGroupName File/Directoryname
chown Newownername File/Directoryname

touch
creates empty file
changes the file timestamp
Example: touch filename

Note: touch command is mostly used in system build time. But


how?

umask
User file creation mode mask 4 digit octal number that unix uses
to determine the file permission for newly created files
(666 umask) value is the default permissions
Exercise: Change the umask value to 000 and create a new file.

more less head - tail


cp /home/cdctrg32/ravi/largefile .;
cat largefile

(Bingo!!!)

more Forward only


less - forward and backward movement
head -10 largefile /* First 10 lines of the file */
tail -10 largefile /* Last 10 lines of the file */ **To view Log Files**

which <command> Displays the path of the commands


whereis <command> - More info than which
whatis <command> - quick introduction about the command
ldd prints library dependencies
Example: ldd /bin/ls
file <filename> - displays the file type

history command
history displays the history of typed commands
Usage: history 20
!! Repeats the last command
!number -> reruns the command given at the given line
passwd To change your password

Das könnte Ihnen auch gefallen