You are on page 1of 74

CTTC SALT LAKE

Linux OS Concepts

Linux
The Linux operating system (OS) was first coded by a Finnish computer programmer called Linus Benedict Torvalds in 1991, when he was just 21! He had got a new 386, and he found the existing DOS and UNIX too expensive and inadequate. In those days, a UNIX-like tiny, free OS called Minix was extensively used for academic purposes. Since its source code was available, Linus decided to take Minix as a model.
4/17/2014 12:11 AM

Operating System
A program or a software that governs the functioning of other programs Interface between User and the Hardware Allocates resources for tasks Allocates tasks to programs Manages space and time Controls the devices

CTTC SALT LAKE

Types of Operating System


Tasks
Uni tasking Multi tasking
Single User Multi User
CTTC SALT LAKE

Users Processing
Uni processing Multi processing

Timesharing

FOSS
Free Open Source Software Free Means Liberty and not related to Price or cost Open Source code is available and any body can contribute to the development. Organization independent
CTTC SALT LAKE

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

CTTC SALT LAKE

Kernel types
Monolithic
All OS related code are stuffed in a single module Available as a single file Advantage : Faster functioning

Micro
OS components are isolated and run in their own address space Device drivers, programs and system services run outside kernel memory space Supports modularity Lesser in size

CTTC SALT LAKE

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

CTTC SALT LAKE

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

CTTC SALT LAKE

4 Freedoms with FOSS


Freedom to run the software anywhere Freedom to study how the programs work. i.e source code will be accessible Freedom to redistribute copies Freedom to improve the software If a software has all these 4 freedoms, then it is a FOSS

CTTC SALT LAKE

Copyleft
Termed by Richard Mathew Stallman Liberates information from the proprietary legal encumbrances associated with conventional copyright Copyleft statement:
Verbatim copying and redistribution are permitted in any medium provided this notice is preserved.
CTTC SALT LAKE

History
Multics 1964 Unics 1969 Minix 1990 Linux 1991
CTTC SALT LAKE

Multics
Multiplexed Information and Computing Service Written in 1964 Timesharing OS Last version was shut down on October 30, 2008 Monolithic kernel

CTTC SALT LAKE

Unics
Uniplexed Information and Computing System Later renamed as UNIX Written in 1969 Ken Thompson, Dennis Ritchie were among the developers Multi user, Multi tasking and timesharing Monolithic kernel

CTTC SALT LAKE

Minix
Minimal Unix Tanenbaum developed this OS Mainly for educational purpose Unix like OS, implemented with Micro kernel. So the name Minix

CTTC SALT LAKE

Linux
Developed in 1991 by Linus Torvalds Used in most of the computers, ranging from super computers to embedded system Multi user Multi tasking Time sharing Monolithic kernel Latest stable version of linux kernel 2.6.28, released on 24-Dec-2008

CTTC SALT LAKE

Free Software Foundation


Founded by Richard Stallman in 1983 Organisation that started developing copylefted programs Project GNU Project
CTTC SALT LAKE

GNU Not Unix Recursive expansion

4/17/2014 12:11 AM

CTTC SALT LAKE

Operating System
User 1

User 2

CTTC SALT LAKE

whats a shell?
The shell is the program that runs when you log in. It prints the prompt and reads what you type, invokes programs, etc.
your window to the Linux world.

use chsh <new shell> to change your shell

Linux OS

CTTC SALT LAKE

Linux Distributions
Redhat Fedora Debian Novells SUSE Linux Ubuntu Mandrake Live CDs Knoppix and more

CTTC SALT LAKE

GNU/Linux
Only the kernel is called by the name Linux The rest are the tools developed under GNU Project Hence the name GNU/Linux

CTTC SALT LAKE

Browsers
Mozilla
First Open source browser Released from Netscape group

Firefox

Sea Monkey

Integrated web application suite derived from the mozilla source code

CTTC SALT LAKE

High performance, feature rich, standards based web browser

Directory structure
/ home user bin usr sbin etc lib bin sbin
25

File Management Commands


mkdir - creating directory
mkdir dirname

rmdir removing directory and its contents cd Change directory


cd dirpath
CTTC SALT LAKE

rmdir dirname

cp Copying files
cp file1 file2

mv Moving or renaming files


mv oldfile newfile

File Management contd..


ln Creating links between files
ln file1 file2
CTTC SALT LAKE

Difference between copying files and linking files


cp src dst
Contents of src will be present in dst Changing content in src will not affect contents of dst and vice versa

ln src dst
Contents of src will be present in dst Changing content in src or dst will get reflected in the other file

Commands
Help about commands man, pinfo, info (man <<cmd name>>) Viewing files content cat <<filename>> Viewing users, processes who List all Users who am I List the current user pstree displays all processes running in the system in tree format ps displays processes owned by the current user Changing file permission/owner chmod changes file permission chown changes file owner

CTTC SALT LAKE

Linux Basics
Freely Downloadable from websites Available as sets of CDs Installation is very simple After installation you can create logins for different users Each user may login by his/her own login and passwd own login area Upon login, default directory is home directory of the user

4/17 /201 4 12:1 1 AM

Linux basics..
Linux/Unix is case sensitive i.e. WHO is not same as who Unix shell is a command program to communicate with a computer Shell interprets the command that you enter on keyboards Shell commands can be used to automate various programming tasks

4/17 /201 4 12:1 1 AM

Linux commands
Usually short and cryptic like
vi or rm

Commands may also have modifiers for advance options like:


ls l and mv R are different that ls or mv respectively

4/17 /201 4 12:1 1 AM

Wildcards
You can substitute the * as a wildcard symbol for any number of characters in any filename. If you type just * after a command, it stands for all files in the current directory:
lpr * will print all files

You can mix the * with other characters to form a search pattern:
ls a*.txt will list all files that start with a and end in .txt
4/17 /201 4 12:1 1 AM

The ? wildcard stands for any single character:


cp draft?.doc will copy draft1.doc, draft2.doc, draftb.doc, etc.

Control characters
You type Control characters by holding down the control key while also pressing the specified character. While you are typing a command:
ctrl-W erases the previous word ctrl-U erases the whole command line

Control commands that work (almost) any time


ctrl-S suspends (halts) output scrolling up on your terminal screen ctrl-Q resumes the display of output on your screen 4/17 /201 ctrl-C will abort any program
4 12:1 1 AM

Help on command line


man : Type

man and the name of a command to read the

manual page for that command.

e.g. man ls

apropos: gives a list of commands that contain a given keyword in their man page header: e.g. apropos ls

4/17 /201 4 12:1 1 AM

Some important commands in Linux


ls, Give a listing of the current directory. Try also ls -l cp, Copy file from source to destination mv, Move file from source to destination. If both are the same directory, the file is renamed vi, Edit a file. vi is one of the most powerful text editors

chmod, Change file permissions


mkdir, rmdir Make/Remove a directory cd, Change directory rm, Remove a file. Can also remove directory tree man ls, Get help for ls. All commands have help
4/17 /201 4 12:1 1 AM

Networking
telnet
Log into a remote host machine. Almost the same as telnet, but uses a different protocol. See if a remote host is up. Transfer files using the File Transfer Protocol. Run the Netscape web browser. Read Internet News. Read your mail using a full-screen display. Read your mail using an ancient command-line program.

rlogin ping ftp


netscape

trn

pine mail who


See who else is logged in.
Talk to someone else who is current logged in. Send a file or set of files to a printer.

talk

lp

4/17 /201 4 12:1 1 AM

Manipulating Files
cat
Concatenate program. Can be used to concatenate multiple files together into a single file, or, much more frequently, to send the contents of a file to the terminal for viewing.

more
Scroll through a file page by page. Very useful when viewing large files. Works even with files that are too big to be opened by a text editor.
A version of more with more features. View the head (top) of a file. You can control how many lines to view. View the tail (bottom) of a file. You can control how many lines to view. You can also use tail to view a growing file. Count words, lines and/or characters in one or more files. Substitute one character for another. Also useful for deleting characters. Sort the lines in a file alphabetically or numerically. Remove duplicated lines in a file. Remove sections from each line of a file or files. Wrap each input line to fit in a specified width. Filter a file for lines matching a specified pattern. Can also be reversed to print out lines that don't match the specified pattern.

less

head

tail

wc

tr

sort

uniq

cut

fold

grep

gzip (gunzip)
Compress (uncompress) a file.
Archive or unarchive an entire directory into a single file. Run the pico text editor (good for beginners). Run the Emacs text editor (good for experts).

tar

pico

emacs

4/17 /201 4 12:1 1 AM

Text Editors Available on Linux Systems


vi
Non-graphical (terminal-based) editor. Guaranteed to be available on any system. Requires knowledge of arcane keystroke commands. Distinctly unfriendly to novices.

emacs
Window-based editor. Primitive menus make it slightly more friendly to novices. Still need to know keystroke commands to use. Installed on all Linux distributions and on most other Unix systems.

xemacs
More sophisticated version of emacs, but usually not installed by default. All common commands are available from menus; however the user interface is still confusing at first. Very powerful editor, with built-in syntax checking, Webbrowsing, news-reading, manual-page browsing, etc.

pico
Simple terminal-based editor available on most versions of Unix. Uses keystroke commands, but they are listed in logical fashion at bottom of screen.

4/17 /201 4 12:1 1 AM

Listing files and Emulating Terminal


Listing files in a directory
ls Lists all files in a directory ls a Lists all files (including hidden files) ls l Lists files in a directory along with owner information, permission etc

Terminal Emulator
xterm Generates a terminal xterm fg color bg color rightbar : Generates a terminal with the specified background and foreground color and a scroll bar on the right side

CTTC SALT LAKE

VI Editor
Popular text editor Just type vi <<filename>> at the prompt and hit the enter key. A new file will be opened Type the contents needed and save To save, press the Esc Key and then press : (colon) w q and then enter To quit with out saving Esc + : + q and then enter

CTTC SALT LAKE

Vi editor
Navigation Left -h Down -j Up -k Right -l Top of the screen H (shift + h) //caps lock will not work Middle of the screen M (shift + m) Bottom of the screen L (shift + l) $ - End Key, 0 Home Key Edit Commands Cut X, x Copy yy, yw Paste P, p

CTTC SALT LAKE

Pattern matching
grep GNU Regular Expression Processor Finds the words / patterns matching with the search and displays the line containing the patterns. Search is limited to a file
CTTC SALT LAKE

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 files 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

CTTC SALT LAKE

C Program in Linux
Open a file with extension .c from the command prompt using vi editor vi hello.c Type the contents and save (Esc : wq!) Compile the file gcc hello.c Run the executable ./a.out Compile file with output option gcc o hello hello.c Run the executable ./hello

CTTC SALT LAKE

Shell Scripting
Shell scripting is the most useful and powerful feature in Linux
Minimizes typing of repetitive command Can schedule jobs to run in the system Can initiate back up activities for system administration Similar to batch files in DOS, but more powerful than Batch files

CTTC SALT LAKE

Working with shell script


Open a file with extension .sh using vi editor We can type any number of commands that we use to type at command prompt Save the file Execute the file
sh file.sh ./file.sh (if the file has execution permission)

CTTC SALT LAKE

Shell Scripts
To Print a line
echo Hello World (Prints Hello World in the screen)

To read a line
CTTC SALT LAKE

read n (Stores the content entered by user in variable n

To Comment a line
# This is a comment Only single line comment is available. For multi line comment, we need to use # symbol in lines which we want to comment.

Loops
For loop
for i in 1 2 3 4 5 //Loops 5 times do Body of the loop done
for (( i=0; i<5; i++ )) do Body of the loop done

CTTC SALT LAKE

While Loop
while [ condn ] do body of the loop done
We need to ensure that the while loop condition is terminated in a finite way

CTTC SALT LAKE

Conditions
We can have if, if else, if elif else and case statements (Nested if statements are also possible
1. if [ condn ] then fi 2. if [ condn ] then else fi 3. if [ condn ] then elif [ condn ] then else fi
CTTC SALT LAKE

Conditions (Case)
case expr in Option1) stmt ;; Option2) stmt ;; *) stmt ;; esac Every option should be terminated with a double semicolon. Denotes default case Case should be termniated with esac

CTTC SALT LAKE

Comparison
For integer comparison we have the following
-eq -ne -lt -gt -le -ge : equal to : not equal to : less than : greater than : less than or equal to : greater than or equal to

CTTC SALT LAKE

Comparison
For string comparison we have
- = : equal to - ~= : not equal to

For logical operators


-a : AND -o : OR

CTTC SALT LAKE

Arrays
Initialising an array
A[0] = 10 A[1] = Hi
${A[0]} : retrieves 10
CTTC SALT LAKE

Using an array Here arrays can contain data belonging to different data types Uninitialised index in arrays will have null value by default

Functions
Local Function
Written at the command prompt Lasts for the current session alone

Global Function
CTTC SALT LAKE

Written in .bashrc file Available as long as the definition is there in .bashrc file

Function in shell script


Available with in the file alone

Parameters
Sample function
Functionname() { echo $1 }
Calling function: Functionname Ram Result: Ram

CTTC SALT LAKE

Environment variables
We can view the environment variables through set or env command The set command will display all the global functions written by the user The env command displays only the variables and not the functions We can reassign values for the variables either temporarily or permanently
Temporary
Type varname=value at the command prompt

Permanent
Type varname=value in .bashrc at the root directory

CTTC SALT LAKE

Aliasing
Alias Alternate name for an entity Entity here refers to command We can give another name or alias name for a command either at the command prompt or in the .bashrc file. The former will be temporary and will vanish if the session ends and the latter will be permanent as long as the definition exists in the .bashrc file
CTTC SALT LAKE

Alias and Unalias


alias newname=oldname Eg alias copy=cp Then we can use copy in the same way we use cp command Eg copy file1 file2 //copies content of file1 to file2 To remove alias use unalias command unalias copy After this we cannot use copy to perform copying function

CTTC SALT LAKE

Linux vs. Windows

Windows
First version of Windows Windows 3.1 released in 1992 by Microsoft. Windows is a GUI based operating system It has powerful networking capabilities, is multitasking, and extremely user friendly

Computer Users

Computer Users Cont.


Many beginner users find Windows easer to use than other operating systems Windows has been enjoying an overall advantage over Linux due to Microsofts market success because of its broad focus aimed at all kinds of users Linux has been primary used by advanced computer users programmers and developers

Fundamental Difference between Linux & Windows


One fundamental difference between the two systems is the fact that Linux is "open source". This means that unlike Windows where you only get access to the compiled programs that you run on your machine, with Linux you also get the original computer code to examine and tweak (modify) at your leisure.

This also goes to show that Linux users are more advanced

Comparing Applications
Linux falls short in the number of different applications available for it. There are much more various applications available for Microsoft since the population of Windows users is greater than Linuxs Since Microsoft is more popular, the Hardware products are aimed at the biggest market Windows, such that the product would be sold and used widely

Comparing Applications Cont.


Linux programs are distributes freely since they are not developed by commercial software companies, but instead are created under the GNU Public License, which makes the software free Linux software lacks the GUI and is therefore not liked by many users Windows has its own share of problems the fact that some software is not compliant for different versions of windows (i.e. Windows 95/98) and that many times the GUI concept is overused such that command arguments cannot be passed to the program

Cost Comparison
Please look at the cost comparison PDF files on the site by Cybersource by clicking on the links Bottom line and Price Comparison.

Cost in 1999
Item Linux NT

Server OS 10 Client access


10 Workstations OS Office Suite Total

$30 0
0 $1690 $1720

$700 $2700
$370 $4080 $9730

Comparing GUI
Linux contains X-Windows with 2 interfaces GDK & KDE Linux offers a choice of four desktops thus allowing the user to work in different windows on different desktop for convenience

Comparing GUI Cont.


Windows, on the other hand, is limited to the way the application windows are laid out on the screen Windows GUI also has been known for its large memory requirements, where it usually uses a huge chunk of RAM for visual components

Linux advantages in Kernel and the OS environment


Linux requires 386 architecture to run. Thus, it is compatible with any improved architecture such as 486, Pentium, Pentium Pro, etc There are drivers available for much many types of hardware devices Linux program installation seems to be easier since it only requires a restart when hardware device has been changed Linux supports multiple copies of the Kernel on the system such that if an error is encountered and the Kernel becomes corrupted, a different copy of the Kernel can be used to boot up the system

Security
Linux seems to be more prepared for protecting itself because of the beginning developments of Linux, UNIX, and FreeBSD which were aimed at top notch security Linux allows does not create registry keys in a way Windows does allowing a user to browse installed components registry keys, which contain important information Linux is more virus proof since viruses malicious programs either cannot be run automatically on the Linux machine, or simply are not capable of being executed on a 386 architecture Windows is often known for a large amount of loop holes

Reliability
OS it must not crash, even under extreme loads. OS should process requests even if the operating system or hardware fails Windows seems to be less stable even though the latest versions of Windows 2000 and XP are far more improved than the incredibly buggy Windows 95

Conclusion
Not enough test benchmarks for Linux to compare it to Windows Linux technology is used wider ( example php scripts ), and software is ported to Linux more often. User should be comfortable with the OS

You might also like