Professional Documents
Culture Documents
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
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
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
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
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
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
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
Minix
Minimal Unix Tanenbaum developed this OS Mainly for educational purpose Unix like OS, implemented with Micro kernel. So the name Minix
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
4/17/2014 12:11 AM
Operating System
User 1
User 2
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.
Linux OS
Linux Distributions
Redhat Fedora Debian Novells SUSE Linux Ubuntu Mandrake Live CDs Knoppix and more
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
Browsers
Mozilla
First Open source browser Released from Netscape group
Firefox
Sea Monkey
Integrated web application suite derived from the mozilla source code
Directory structure
/ home user bin usr sbin etc lib bin sbin
25
rmdir dirname
cp Copying files
cp file1 file2
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
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
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
Linux commands
Usually short and cryptic like
vi or rm
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
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
e.g. man ls
apropos: gives a list of commands that contain a given keyword in their man page header: e.g. apropos ls
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.
netscape
trn
talk
lp
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
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.
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
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
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
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
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
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
Shell Scripts
To Print a line
echo Hello World (Prints Hello World in the screen)
To read a line
CTTC SALT LAKE
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
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
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
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
Comparison
For string comparison we have
- = : equal to - ~= : not equal to
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
Parameters
Sample function
Functionname() { echo $1 }
Calling function: Functionname Ram Result: Ram
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
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
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
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
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
$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
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