Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Introduction
Linux refers to the family of Unix-like computer operating systems using the Linux kernel. Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers and video game consoles, to mainframes and supercomputers Linux is a leading server operating system, and runs the 10 fastest supercomputers in the world. The development of Linux is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed, both commercially and non-commercially, by anyone under licenses such as the GNU General Public License. Typically Linux is packaged in a format known as a Linux distribution for desktop and server use. Some popular mainstream Linux distributions include Debian (and its derivatives such as Ubuntu), Fedora and opens USE. Linux distributions include the Linux kernel and supporting utilities and libraries to fulfill the distribution's intended use. Linux is a true 32-bit operating system that runs on a variety of different platforms, including Intel, Sparc, Alpha, and Power-PC (on some of these platforms, such as Alpha, Linux is actually 64-bit). There are other ports available as well, but I do not have any experience with them.
There are two ways to install Linux:Graphical mode :- If you have installed Linux before you can choose
either. The graphical install is better for you if you are a new user because you are guided through every step with help in the side pane.
Text mode: The text-based install allows you more control over what is going
on during the install. This, however, requires some experience with installing Linux
History of Linux
Linux is the first truly free Unix-like operating system. The underlying GNU Project was launched in 1983 by Richard Stallman originally to develop a Unixcompatible operating system called GNU, intended to be entirely free software. Many programs and utilities were contributed by developers around the world, and by 1991 most of the components of the system were ready. Still missing was the kernel. Linus Torvalds invented Linux itself. In 1991, Torvalds was a student at the University of Helsinki in Finland where he had been using Minix, a non-free Unixlike system, and began writing his own kernel. He started by developing device drivers and hard-drive access, and by September had a basic design that he called Version 0.01. This kernel, which is called Linux, was afterwards combined with the GNU system to produce a complete free operating system. On October 5th, 1991, Torvalds sent a posting to the comp.os.minix newsgroup announcing the release of Version 0.02, a basic version that still needed Minix to operate, but which attracted considerable interest nevertheless. The kernel was then rapidly improved by Torvalds and a growing number of volunteers communicating over the Internet, and by December 19th a functional, stand-alone Unix-like Linux system was released as Version 0.11. On January 5, 1992, Linux Version 0.12 was released, an improved, stable kernel. The next release was called Version 0.95, to reflect the fact that it was becoming a full-featured system. After that Linux became an underground phenomenon, with a growing group of distributed programmers that continue to debug, develop, and enhance the source code baseline to this day. Linux continued to be improved through the 1990's, and started to be used in large-scale applications like web hosting, networking, and database serving, proving ready for production use. Version 2.2, a major update to the Linux kernel, was officially released in January 1999. By the year 2000, most computer companies supported Linux in one way or another, recognizing a common standard that could finally reunify the fractured world of the Unix Wars. The next major release was V2.4 in January 2001, providing (among other improvements) compatibility with the upcoming generations of Intel's 64-bit Itanium computer processors.
2.Stability:Linux doesnt need to be rebooted periodically to maintain performance levels. It doesnt freeze up or slow down over time due to memory leaks and such. Continuous up-times of hundreds of days (up to a year or more) are not uncommon.
3. Performance:Linux provides persistent high performance on workstations and on networks. It can handle unusually large numbers of users simultaneously, and can make old computers sufficiently responsive to be useful again.
4.Network friendliness:Linux was developed by a group of programmers over the Internet and has therefore strong support for network functionality; client and server systems can be easily set up on any computer running Linux. It can perform tasks such as network backups faster and more reliably than alternative systems.
5.Flexibility:Linux can be used for high performance server applications, desktop applications, and embedded systems. You can save disk space by only installing the components
needed for a particular use. You can restrict the use of specific computers by installing for example only selected office applications instead of the whole suite.
7.Choice:The large number of Linux distributions gives you a choice. Each distribution is developed and supported by a different organization. You can pick the one you like best; the core functionalities are the same; most software runs on most distributions.
8.Fast and easy installation:Most Linux distributions come with user-friendly installation and setup programs. Popular Linux distributions come with tools that make installation of additional software very user friendly as well.
9.Full use of hard disk:Linux continues work well even when the hard disk is almost full.
10.Multitaskin:Linux is designed to do many things at the same time; e.g., a large printing job in the background wont slow down your other work.
11.Security:Linux is one of the most secure operating systems. Walls and flexible file access permission systems prevent access by unwanted visitors or viruses. Linux users have to option to select and safely download software, free of charge, from online repositories containing thousands of high quality packages. No purchase transactions requiring credit card numbers or other sensitive personal information are necessary.
Installing Linux
Choosing an Installation Method
There are a number of different ways in which you can install your system. They are all documented further later in the chapter. They are as follows: CD-ROM: This method needs a boot floppy, bootable CD, or a PCMCIA boot disk. This is the most common way to install your system. Hard Drive: This method requires you to have the Red Hat installation files on your hard drive. To install Red Hat Linux from a hard drive, you need the same startup and supplemental disks used by the FTP install. You must first create a Red Hat directory called RedHat at the top level of your directory tree. Everything you install should be placed in that directory. Copy the base subdirectory and then copy the packages you want to install to another subdirectory called RPMS (Red Hat Package Manager). Basically, these are your program installation files. You can use available space on an existing DOS partition or a Linux partition that is not required in the install procedure (for example, a partition that would be used for data storage on the installed system). With Red Hat 7 being a 3-CD install, there is going to be the overhead of having enough space free to store these files.If you are using a DOS filesystem, you might not be able to use the full Linux filenames for the RPM (Red Hat Package Manager) packages. The installation process does not care what the filesystem looks like, but it is a good idea to keep track of it so you will know what you are installing. NFS (Network File System) Image: You can install from an NFS server that has the install files exported. This requires a network or PCMCIA boot disk. You should either have nameservices configured or know the NFS server's IP address and the path to the exported CD-ROM. This method is only advisable if the NFS server is on a local network. It will take a long time to install using this, the FTP, and the HTTP install method. There is the possibility of the connection timing out. FTP (File Transfer Protocol) and HTTP: Comparable to an NFS image install. This also requires a network or PCMCIA boot disk. You must have a startup disk and a supplemental disk for an FTP install. You need to have a valid
6
nameserver configured or the IP address of the FTP or HTTP server you will be using. You also need the root path of the Red Hat Linux directory on the site.
This is only the name of the devices as Linux sees them. The actual way Linux views your partitions is
hda1: Primary partition on first hard drive. hda5: Extended partition on first hard drive. The extended partition will
is a hog on RAM and will generally use up to 50% of your RAM, so it makes sense to have a decent sized swap file. A better way to estimate how much RAM you need is to figure out the size of all the programs you would run at one time. To this number, add 24MB to cover the OS. If the total is less than 64MB, use a 64MB swap space; otherwise, use the actual value. These days, with most machines coming with 64MB128MB of RAM a swap space of 80MB100MB is about right. You should always configure some swap space, regardless of how much RAM you have. Even a small amount of swap space will have good results on a system with a lot of RAM. For example, I have 256MB of RAM on my system, which is more than enough for all of the programs I run. I have 127MB of swap space for programs I have running but am not actively using. To create your swap partition using fdisk, you need to use n for a new partition. Choose either primary or extended; you most likely need primary. Give the partition a number and tell it where the first cylinder should be. Last, tell fdisk how big you want your swap partition. Now you need to change the partition type to Linux swap. Enter t to change the type and enter the partition number of your swap partition. Enter 82 for the hex code for the Linux swap partition. You have created your Linux and Linux swap partitions, and it is time to add any partitions you might need (for example, Windows 95). Use n again to create a new partition and enter all the information just as before. However, after you enter the size of the partition, you need to change the partition type. Enter l to get a listing of the hex codes for the different partition types. Find the type of partition you need and use t to change the partition type. Repeat this procedure until all your partitions are created. You can create up to four primary partitions; then you must start putting extended partitions into each primary partition. After your partitions are created, the installation program looks for Linux swap partitions and asks to initialize them. Choose the swap partitions you want to initialize, select the Check for Bad Blocks During Format box, and click OK. This formats the partition and makes it active so Linux can use it.
Commands of Linux
In Linux, the commands are interpreted by a command-line interface called shell. Shell provides a user interface that responds to particular commands, programs or scripts that a user creates. The default Red Hat Linux shell is known as Bourne Again Shell or bash. The Linux shell has various shell commands to run programs, manage Linux files and interact with the computers hardware.
File Commands:File commands are used to remove, rename or move files in the directory structure. You can also display the contents of a specified file using these commands. The file commands create new files by copying the contents of one file into another file. The various file commands are:
cat > command:-The cat > command is also used for creating a file. You
should now know how to create small files. Enter the command cat, followed by the > (the right chevron) character and the filename. Ctrl+Z command is used to Save the contents of the existing file. Its Syntax is:[root@linux Msc(IT)(LE)]# cat > filename For ex--[aman@linux Msc(IT)]# cat > deep I am the student of Msc IT class. ^z [1]+ stopped cat > deep These are options of cat command:-E, --show:-ends display $ at end of each line. -n, --number:- number all output lines. -T, --show-tabs:- display TAB characters as ^I
For ex[aman@linux Msc(IT)]# cp deep randeep [aman@linux Msc(IT)]# These are the options of cp command:-l, --link:link files instead of copying -Z, --context=CONTEXT:- set security context of copy to CONTEXT
10
more command:-If a file is too large for its contents to fit in one screen, it will
scroll off your screen when you view it with cat command, but more command views the contents of a file, Page Wise. The more command displays the first page of the contents of a file existing in the current working directory. Its syntax is:[root@linux Msc(IT)(LE)]# more filename For ex--[aman@linux Msc(IT)(LE)]# more sunny [aman@linux Msc(IT)(LE)]# These are the options of the more command:-p Do not scroll. Instead, clear the whole screen and then display the text. -p Do not scroll. Instead, clear the whole screen and then display the t-num.This option specifies an integer which is the screen size.
For ex--[aman@linux Msc(IT)]# wc randeep [aman@linux Msc(IT)]# These are the options of wc command:wc -l filename will print total number of lines in a file. wc -w filename will print total number of words in a file. wc -c filename will print total number of characters in a file.
cmp command:-The cmp (compare) command is used to Compare the two files.
Obviously, it needs two filenames as arguments. Its syntax is:[root@linux Msc(IT)(LE)]# cmp firstfilename secondfilename For ex--[randeep@linux Msc(IT)(LE)]# cmp aman sunny These are the options of cmp command:-l :- Print the byte number (decimal) and the differing byte values (octal) for each difference. -s :- Print nothing for differing files; return exit status only.
12
Directory commands:In Linux, directory commands are used to create and delete directories in a file system. You can also display the contents of a directory using these commands. The contents of a directory are the files and sub-directories stored in a particular directory. The various directory commands are:
SSSS1
13
Options: rm -r directory_name will remove all files even if directory is not empty. rmdir parminder is how you use it to remove parminder directory. rmdir -p will remove directories and any parent directories that are empty. rmdir -s will suppress standard error messages caused by -p.
15
cal command:-With the cal (CALENDAR) command, you printed the calendar
for a month on the Screen. Any calendar from the year 1 to 9999 can be displayed with this command. Its syntax is:[root@linux root]# cal yearname For ex--[root@linux Msc]# cal -1 March 2011 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 who command:-Linux maintains an account of all the current users of the system. Its a good idea to know the people working on the various terminals so that you can send them messages directly. Its syntax is:[root@linux root]# who These are the options of who commands:-b, --boot: time of last system boot -m :- only hostname and user associated with stdin -q, --count:- all login names and number of users logged on su command:-The su command facilitates you to switch b/w user accounts. You can change the control from a user account connected to the shell prompt to another user account by using a login ID and password of the user. Its syntax is:[root@linux root]# su newusername For ex--[root@linux root]# su sandeep These are the options of su command:-l, --login:- make the shell a login shell -c, --command=COMMAND:- to the pass a single COMMAND shell with -c
16
17
These are the options:-b option will precede each line with its block number. -c option will only print the count of matched lines. -i ignores uppercase and lowercase distinctions. -l lists filenames but not matched lines.
-B:-use size-byte blocks. -H:-likewise,but powers of 1000 not 1024. free command:-The free command is used to display the all free space in system. Its syntax is:[root@linux Msc(IT)(LE)]# free These are the options of free command:-b:-It switch displays the amount of memory in bytes. -t:-It switch displays aline containing the total. -l:-It switch shows detailed low and high memory statistics.
20
These are option of mount command:-h:-print help message. -v:-print a version of string. umount command:-The umount command is used to close the various hardware devices such as CD-ROM and floppy drive. Its syntax is:[root@linux Msc(IT)(LE)]# umount / dev/cdrom
Wild card entry Command:These command are used for wild card entries. i) ? - This is used for the read the single character from the file name or extension of the file. Its syntax is: [root@linux root]# ls Sunny?.txt This command catch all the txt files those starts from such and have 4 previous character. *- This command used for read all the character and extension of files. Its syntax is : [root@linux Msc(IT)(LE)]# ls *.* This shows the list of all files presents in the current directory.
ii)
21
22
Vi editor
All Linux configuration files are written in plain English, easy to read and to adapt. You use a text-editor to write or make changes to such files. The two most popular, powerful, and unfortunately "difficult" text editors, both of which are found in every Linux distro, are Vi and Emacs. Most GUI-based editors, such as Kedit, are easier to manage. But don't make the mistake of thinking that a GUI-based editor is all you need. There are situations that crop up with Linux that require a text-mode editor -- in other words, when you don't have the luxury of accessing a GUI desktop at all. Vi and Emacs are the only tools that come with every Linux distro that work in text mode, so learning one or the other is mandatory. (For Windows and DOS aficionados, think MS-DOS's Edit and Edlin programs.) Which one's better? Vi and Emacs fans are fond of waging war on that question. In this edition of Linux Explorers, we're picking your text editor for you. This one is all about the Vi text editor, because that's the one we prefer. Vi was originally developed by William Joy at Berkeley University and first officially included in AT&T System 5 Unix. It started out as a line-oriented editor for dumb terminals. The Vi editor, or Vi iMproved (VIM) is an enhancement by Bram Moolenaar; it's the version that people use today.
2. Insert mode:-(entered text is inserted into the file Press the <Esc>
(Escape) key to go to the command mode).
23
Getting started
To start Vi, open a terminal or console and simply type "vi" (without the quotation marks) followed by the name of any existing file or a new file you want to create. Vi works in two main modes, one for editing text and the other for giving commands. To switch between the two modes you use the I and Esc keys. The program opens in the Command mode, which is used for cursor movements, delete, cut, copy, paste, and saving changes. The Insert mode is what you'll work in most of the time. You use it to make changes in an open file. Enter the Insert mode by pressing the I key. Newer Vi versions will display the word "INSERT' on the bottom line while you're in Insert mode. Press the Esc key to switch Vi back to Command mode. As soon as you hit the Esc key the text "INSERT" on the bottom line disappears. You save your changes to the open file from the Command mode. Press Shift-ZZ to save.
24
Command
i a /word n w e b 3b yy dd 3dd D dw x o O CTRL-w u U
Description
insert mode, (ESC to exit insert mode) allows text to be entered on the screen Append to right mode Move to the occurrence of "word" Locate the next occurrence Advance to the next word Advance to the next end of a word Move to the previous word Move backward 3 words Copy line (then move cursor and use p to paste after current cursor line) delete line delete 3 lines Delete remainder of a line Delete word Delete character Open space for new line below the cursor line Open a line above the cursor Move back a word in append mode Undo last Undo all changes to current line
25
In command mode, repeat the last text changing the command on the current line
:w newfilename save the file to newfilename from the command mode :wq :q! r J s cw c cc h H L M G 0 (zero) view filename set number set nonumber save and quit quit without saving replace then typa a character ot be replaced with r then return to break up a line join 2 lines substitute (sentence) typed text over a character, ESC when done change word change part of a line from the cursor to the end of the line substitute new text for aline, ESC when done move the cursor back one space move the cursor to the highest line on the screen move the cursor to the lowest line on the screen position the cursor at the midpoint on the screen last line in the file Move the cursor to the beginning of the line it is on Open a file for viewing only Turn on line numbers Turn off line numbers
26
27
Introduction of Linux Shell:A shell is a program that acts as an interface between the user and the kernel whereas the kernel acts as the interface between the hardware and the user while working with Linux operating system. The shell interprets the commands typed at the terminal by the user and converts those commands into the kernel readable from. The shell is also termed as a Command-line interface through which the commands are interpreted. Various types of shells as the Bourne and the C are provided by the Linux operating system. All the shells installed on the Linux operating system are viewed using the files /etc/shells.
Korn shell:-The executable file of the Korn shell is ksh and is installed
at /bin/ksh. The korn shell incorporates the features of both the Bourne shell and the C shells.
bash shell:-The executable file of the bash shell is /bin/bash. Tcsh shell:-The Toms C (Tcsh) shell shell is an enhancement to the C
shell. The Tcsh shell is executed by typing either csh or tcsh at the shell prompt. ASH shell:-The ASH shell is a lightweight Bourne shell, which is usually suitable for computers that have limited memory.
28
Shell Scripiting:All shell statements and LINUX commands can be entered in the command line itself. However, when a group of commands has to be executed regularly, they are better stored in a file. All such files are called shell scripts, shell programs, or shell procedures. The shell has a whole set of internal commands that can be stringed together as a language, with its own variables, conditionals and loops. What makes shell program powerful is that an external command can also be used as a control command for any of the shells constructs. In which used all Conditional Statements like as if Statement, case Statement; Iteration Statements: for Statement, while Statement, until Statement, etc. All Statements explain with examples.
Numeric Comparison with test:When you utilize if to evaluate expressions, the test statement is often as its control command. Moreover, the relational operators also have a different form when used by test. They always begin with a (hyphen), followed by a twocharacter word, and enclosed on either side by white space. The complete set of operators is shown in Table.
Meaning
Equal to Not equal to Greater than Greater than or equal to Less than Less than or equal to
29
if Statement:-
The if statement, like its counterpart in other programming languages, takes two-way decisions, depending on the fulfillment of a certain condition. Every if has must have a corresponding fi. In the shell, the statement uses the following form. If condition is true
then
Output:The value of a is 4
30
if also permits multi-way branching; you can evaluate more conditions if the previous condition fails. The shell also has a if-then-fi, if-then-else-fi, and if-thenelif-then-else-fi, where you can have as many elif s as you want, while the else remains optional
31
Output:Enter the 1st number=15 Enter the 2nd number=49 Enter the 3st number=35 y is big number
Example: WAP to print the Any Day of week using ifthen-elif-then-else-fi in shell scripting.
Echo n Enter Any no= read a if [ $a eq 1 ] ; then echo RED elif [ $a eq 2 ] ; then echo GREEN elif [ $a eq 3 ] ; then echo YELLOW elif [ $a eq 4 ] ; then echo BLUE elif [ $a eq 5 ] ; then echo ORANGE elif [ $a eq 6 ] ; then echo PINK else
32
The case statement is the second conditional offered by the shell. The statement matches an expression for more than one alternative, and user a compact construct to permit multi-way branching. It also handles string tests, but in a more efficient manner than if. The general syntax of the case statement is as follows: case expression in pattern1) execute commands ; ; pattern2) execute commands ; ; pattern3) execute commands ; ; esac
case matches the expression first for pattern1, and if successful, executes the commands associated with it. If it doesnt then it falls through and matches pattern2, and so on. Each command list is terminated by a pair of semi-colons, and the entire construct is closed with esac (reverse of case).
33
Example: WAP to print the Arithmetic Operator using the case statement in shell scripting.
echo n Enter the 1st number= read a echo n Enter the 2nd number= read b echo n Press any no 1 to 5= read c case $c in 1) let d=$a+$b; echo Sum of two nos=$d ;; 2) let d=$a-$b; echo Subtraction of two nos=$d ;; 3) let d=$a*$b; echo Multiplication of two nos=$d ;;
4)
34
let d=$a/$b; echo Division of two nos=$d ;; 5) let d=$a%$b; echo Modulus of two nos= $d ;;
Output:Enter the 1st number= 20 Enter the 2nd number=2 Press any no 1 to 5=3 Multiplication of two nos=40
35
The for statement:The for loop is different in structure from the ones used in other programming languages. There is no next statement here, neither can a step be specified. Unlike while and until, it doesnt test a condition, but uses a list instead. The syntax of this construct is as follows: for variable in list do execute commands done The loop body is the same, but the additional parameters here are variable and list. The loop body is executed as many times as there are items in the list.
36
Example: WAP to print the any Table using for loop in shell scripting.
echo n Enter any no you want display the Table= read a p=1 i=1 for i in 1 2 3 4 5 6 7 8 9 10 do l=$a*$i echo n$l= let p=a*i echo $p let i+=1 done
Output:Enter any no you want display the Table=7 7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42
37
Example: To print the following output using for loop in shell scripting.
* * * * * * * * * * J=1 for i in 1 2 3 4 do for j in 1 2 3 4 do if [ $j-le $i ] ; then echo n * fi let j+=1 done echo done
38
Example: To print the following output using for loop in shell scripting.
1 1 1 1 2 2 2 3 3 4
J=1 for i in 1 2 3 4 do for j in 1 2 3 4 do if [ $j le $i ] ; then echo n $j fi let j+=1 done echo done
Example: WAP to print the Factorial using for loop in shell scripting.
echo n Enter any number= read a fact=1 for i in 5 4 3 2 1 do let fact=fact*i
39
while statement:The while statement should be quite familiar to most programmers. It repeatedly performs a set of instructions till the control command returns a true exit status. The general syntax of this command is as follows: while condition is true do execute commands done The set of instructions enclosed by do and done are to be performed as long as the condition remains true.
Example: WAP to print the Factorial using while loop in shell scripting.
echo n Enter any number= read n i=1 fact=1 while [ $i gt $n] do let fact=fact*i let i+=1 done echo Factorial is=$fact
41