Você está na página 1de 76

UNIX FUNDAMENTALS

Sun Microsystems
Vikash Sharma

CONTENTS What is an Operating System ? About Unix Operating System

Details - Kernel, Shell and Directory Hierarchy


Unix System Commands

What is an Operating System ?

An Operating system (OS) is a collection of files and directories that interacts between the hardware and the software of the system An OS is a software which is initially loaded into a systems harddisk by a boot program to manage all the other programs in a computer All major computer platforms (Hardware and Software) require an OS

Examples of OS
LINUX WINDOWS

XP,2000

HP

UX

IBM

AIX - OS

SOLARIS

MAC

UNIX OPERATING SYTEM


It was developed originally at AT&T Bell Laboratories in 1969 by Ken Thompson and Dennis Ritchie Modifications were made to the original source code at the University of California at Berkeley which resulted in the Berkeley Software Distribution (BSD) UNIX. One of the important modifications in the UNIX OS made by the programmers at Berkeley was the addition of networking software which enabled the OS to function in a Local Area Network (LAN)

The PDP-7

In a few years individual companies came out with their own form of the originally created BSD Unix by adding more tools and making modifications in the source code. In 1988 some OS were folded together to make the System V release 4(SVR4) UNIX. The SVR4 became the basis for many OS like Solaris,Hp UX,Linux,Ibm AIX.

Ken Thompson and Dennis Ritchie at work

UNIX OS Solaris

The Unix OS is made up of three major components KERNEL SHELL DIRECTORIES

Commands Shell Kernel Hardware

Kernel is the core of the Unix OS The kernel interacts between the software and the hardware in a system. It manages all the physical resources in the computer including File Systems, Device Management, Process Management, Memory management...etc.. The kernel (Static core of an OS) is made up of two modules Genunix and Unix Shell is the primary command interpreter It accepts the commands that the user enters, it then interprets these commands and passes it to the kernel. The kernel then executes the commands in regards to what the user has requested.

Types of Kernels

Monolithic Kernel

MicroKernel

In a Monolithic Kernel all OS services run along with the Kernel residing in the same area. Monolithic kernels are dependent upon the system components (Such as hardware and software components)
Microkernel are micro hardware components that interacts with the software of the OS to perform services Memory Management, Multitaskingetc

Types of Shells

Bourne Shell

Is the original Unix system Shell

C Shell (csh) Has added feature (CMD line history, Job controletc..) Korn Shell (ksh) Is a combination of the Bourne Shell and has C Shell like enhancements with more added features (Command Line Editing) Bash Shell (bash) (Bourne Again Shell) Is a combination of the Korn Shell and C Shell

Z Shell (zsh) It resembles the Korn Shell but with many other added enhancements TC Shell (tcsh) It resembles the C Shell but with many other added enhancements

Primary Shells of the Solaris 10 OS Bourne Shell - Korn Shell C Shell

Default Shell for the root ( / ) user is the Bourne Shell

DIRECTORY HIERARCHY

It makes up the File System which is a organized group of directories and files that help in running applications. It is also a method for storing files and organizing computer files. It uses a data storage device such as a hard disk or a CD ROM.

Solaris

The Solaris 10 OS is a virtual memory operating system. (It enables execution of programs as if more memory is available than the physical RAM) It consists of SunOS 5.x, Open Network Computing (ONC+) Software

UNIX SYSTEM COMMANDS

Unix system commands instructs the system to perform specific functions A Command Syntax consists of a Command name, Options and Arguments Commands in Unix are case sensitive The behavior of command functions can be altered by using Options and Arguments The preferred mode of login in an Unix environment is the Command Line login

Basic Commands in Unix OS

uname Provides information about the system ( SunOS )


date Displays the current Day, Month, Date, Time
(hh:mm:ss), Greenwich Medium Time, Year

cal Displays a calendar for the current month and year; bc


command invokes a calculator

clear To clear the current terminal window

Using Commands with options


When an option is added to a command it alters the output of what is displayed Commands are case sensitive Multiple options can be used with a single command Multiple options can be listed out separately or combined after a dash (-)

Examples of Commands with options

uname i Provides information about the system along


with the hardware platform

uname n Provides the host name of the system uname a Shows the information currently available on
the system

Using showrev command

showrev This command display the systems information with the Host ID

Using Commands with Arguments

Enables the user to define exactly what he/she wants to do with the command

Example of a Command with an Argument cal 12 2004 1st argument specifies the month and 2nd argument specifies the year that needs to be viewed

File Types

NAME Regular Files Directories Symbolic Links Block special device files Character special device files

SYMBOL d l b c

Using ls Command

The ls command lists the files in a directory

The l option provides additional information about the files

The filename (dir1) argument specifies the file to be viewed

ls a Displays the hidden files in the directory

A single period ( . ) represents the current working directory and the double period( ..) represents the parent directory which contains the working directory

Using cd Command

When logged into the system by default the current working directory is the users home directory. The cd command is used to navigate between directories in the directory hierarchy

To return to the users home directory ( cd )

Using pwd Command

This command shows the present working directory

Using the mkdir Command

The mkdir command is used to create a directory

mkdir p newdir /empty The p option checks for directory (If directory does not exist, a directory is created - newdir) and then creates the directory - empty

Using the rmdir / rm r Command

The rmdir / rm r command is used to remove directories

Using cp Command

This command copies directories and files from one location to another location To copy a file To copy a dir

Using mv Command
-- Moves a directory into the destination

directory

When the destination directory exists, the mv command moves the directory into the destination directory

This command moves or renames a directory -- Renames a directory when a destination directory does not exist

Different ways to create a file

Creating a file through touch Command

Creating a file through cat Command Creating a file through vi Editor

Using touch Command

The touch command is used to create a zero byte file and it puts a time stamp on an existing file

To run certain programs a required set of zero bytes files are required

Creating a file through cat Command

cat Command is used to create, read, and append a file Creating and Reading a file

Appending an existing file

Note : Files cannot be edited when using cat command

Creating a file through vi Editor

It is an interactive editor that can be used to create and modify text files It is the only text editor that can be used to edit certain system files without changing the permission of the files All changes in the vi editor takes place in the buffer, and changes can be written to the disk or can be discarded

Using file Command

The file command tells you the property of file or directory

ASCII text: American standard code of information interchange

Using more Command

The more command displays the content of a file in a page wise display

Using head Command

The head command displays the contents of a file with ( - ) options

Using tail Command

The tail command displays the contents of a file with ( - ) and ( + ) options

Using sort Command

The sort command displays file contents in ascending or descending order

Using the wc Command

The wc (Word Count) command displays numbers of lines, words, characters, memory size

Using which Command

The which command shows the location of the commands From where the command is executed

Using echo Command

The echo command shows the value of the given variable or shows the variables environmental path

Using grep Command

The grep command identifies the line with the matching pattern and displays it. Multiple options can be used along with grep Examples of options along with grep command ( -n ) Displays the line number along with the contents of the line ( -v ) Displays lines that do not match with the given pattern

grep Command with n & -v options

Using egrep Command

The egrep command searches the contents of one or more files with the matching pattern It uses extended regular expression metacharacters (Metacharacters of the grep command plus some additional metacharacters) + Matches one or more metacharacters x|y Matches either x or y

Using egrep with ( | ) option

Using egrep with ( + ) option

Using pgrep Command

The pgrep (Process grep) command displays the Process ID along with the Parent Process ID

Using find Command

The find command is used to find a directory or file in the system ( find /(dir name) option (dir/file name )

Using find Command with multiple options

find Command with optionscont.

Using su Command

This command is used to switch over from one user (ex: root) to another user (ex: user1)

Using who Command

The who command shows the users information Options in the who Command
who who

am i whoami

Who, who am i, whoami

Using the id Command

The id command shows the users ID and Primary group ID

Using finger Command

The finger command displays the information of a user along with the user status

Using ln Command

The ln command is used to create a Symbolic link and Hard link Symbolic Link It is a link between a source file and a destination file. If the source is deleted the destination file does not exist.

Hard Link This is also a link between a source file and a destination file. If the source is deleted the destination file still exists

File Permissions
r Readable/ w Writable/ x Executable/ ( - ) - Denied

Owner Permissions of the owner of the file or directory Group Permissions for all the members of the group to who the file or directory belongs to Others Permissions for all other users except the owner and the group to who the file or directory belongs to

Examples of Permissions
- This file has Read, Write and Executable permissions set for the Owner of the file only - This directory has Read and Execute permissions set for the Owner and Group of the directory - This file has Read, Write and Execute permissions for the Owner. It also has Read and Execute permissions for the Group and Others

Octal value for Permissions

Combination of values and permissions

Default UMASK Value is 022. To view the umask value the command is (# umask )

To view the path where the umask value is set more /etc/default/login
OCTAL VALUE UMASK VALUE

OWNER 7 (-) 0

GROUP 7 (-) 2

OTHERS 7 (-) 2

Changing File Permissions Chmod 777 filename/dir

DEFAULT PERMISSION ( Dir / File )

Using the VI (Visual Display) Editor

The vi editor is a command line editor that has three different modes ( Case Sensitive Editor) Command Mode Edit Mode Last Line Mode

Command Line Mode: It is the default mode for the vi editor. Commands can be entered to delete, change, copy and move text in a file and also used to position the cursor ( vi filename )

Edit Mode: This mode is used to enter text in a file ( i, o, a, etc..) Last Line Mode: This mode enables the user to edit advanced commands such as to save a file ( : ) Cursor moves to the last line of the screen ex: ( q!) Exits the vi editor without saving a file ( :wq! ) Saves a file and exits the vi editor

Editing Commands in VI Editor


i ----- Inserts text before the cursor a ----- Appends text after the cursor o ----- Opens a new line below the cursor
O ----- Opens a new line above the cursor A -----Appends text at the end of the line I ----- Inserts text at the beginning of the line

w ----- Moves one word forward b ----- Moves one word back e ----- Moves to the end of the current word

$ ----- Moves to the end of the line 0 (Zero) ----- Moves to the beginning of the line Return key ----- Moves to the beginning of the next line G ----- Moves to the last line of the file 1G ----- Moves to the first line of the file :n ( ex - :5 ) ----- Moves to the specified line (Line 5) Ctrl F ----- Moves one page forward Ctrl B ----- Moves one page back R ----- Overwrites and replaces characters at cursor
position and to the right of the cursor C ----- Overwrites and replaces character from cursor to the end of the line

x ----- Deletes a character at the cursor dd ----- Deletes the line containing the cursor D ----- Deletes the line from the cursor to the right end of
the line u ----- Undoes previous command U ----- Undoes all changes to the current line r ----- Replaces the character at the cursor with another character

. ----- Repeats the previous command yy ----- Copies the line P ----- Places the copied line below the cursor p ----- Places the copied line above the cursor

:w ----- Saves the file with changes


:w filename ----- Saves the file with a new filename

:wq! ----- Saves the file with changes and quits the editor :q! ----- Quits without saving the file

Você também pode gostar