Linux lesson 2

Page 1

SA1 LECTURE 2 LINUX BASICS: Linux Features:

Free Operating System: Linux is completely free operating system although there are some commercial Linux distributions available but still there are hundreds of free distributions.

Open Source: Linux is open source operating system. A Linux distribution has to provide source code with actual operating system.

Less Virus Problems: There are many features of Linux/Unix operating system that make it resistant against viruses. 1. In Linux by default a user do not have enough rights on Linux file system and operating system to disturb or disrupt the operating system’s important areas and functions. 2. In Linux we do not have centralized registry concept and no hard and fast pre defined place of configuration information. Like in windows we have a centralized hierarchical registry in which places are predefined and therefore people know that if they have to destroy an application then they can do this from which place in registry. A number of viruses that effect registry have been developed BUT for Linux development of such processes is very much difficult. 3. Linux is open source. As soon as a version is launched its source code is also provided to on the internet and people from all over the world study it and takes out it’s bugs and security problems. Removal of bugs and security problems makes Linux resistant against viruses.

Complete Operating System: Linux is a complete operating system With windows you have to buy many software Like Office Products, Graphic Products, Mail and Proxy servers anti viruses etc. etc. Linux comes built-in with all needed software.

Reliable: Linux is reliable operating systems because it does not have virus problems, Linux does not have crash problems.

Improved Performance: On Linux servers GUI is not recommended. Without GUI Linux is very much good in performance and less resource hungry. Third Party Support: Linux now have captured third party software and hardware companies and now companies are producing device drivers of their products and new products are being made for Linux.

There are many other features that are normally found in all operating systems like multi tasking, multi processor etc. etc.

NOTE:

PLEASE MAKE YOUR OWN INSTALLATION NOTES IN CLASS.

Run Levels: Run level is a mechanism that defines/configures status of a system. Actually the services that a being start in a runlevel defines the system status. There is a set of directories that configures 0 to 6 run levels in Linux. Therefore there can be 6 status of a system. Following are the default behavior of run levels and we can change this default behavior like we can start NFS service in runlevel 2.


Default Run Level Behavior: Run level Number 0 1 2 3 4 5 6

System Status in This Run Level Shutdown, close all services and start kill services and shut down system Maintenance Mode, close all services and take system in single user mode Start Network and multi user mode but do not start NFS (nfs service) Start Network and NFS server but do not start GUI interface (xfs service) Undefined Start Network, NFS and GUI Reboot, close all services and start kill and reboot services

Note: There are a lot of services in a system that are started in a runlevel but runlevels are defined only on the basis of Network, NFS and GUI services. /etc/rc.d (recourse directory) contains all those directories that defines a different runlevels / system status. Each runlevel has its own directory (like runlevel 0 has /etc/rc.d/rc0.d) directory. In /etc/rc.d/init.d (initialization directory) Linux system keeps services’ startup scripts that are used to start, stop, reload or restart a service. Run level directories (/etc/rc.d/rc0.d to /etc/rc.d/rc6.d) contains shortcuts to the scripts present in /etc/rc.d/init.d with names starting either S or K and after that a number.

Like: /etc/rc.d/rc0.d/K90network -------> /etc/rc.d/init.d/network /etc/rc.d/rc3.d/S10network -------> /etc/rc.d/init.d/network K: 90: S: 10:

(-------> Link /Shortcut of) (-------> Link / Shortcut of)

Kill / Stop this service Stop the service at this number. Means first stop services with less number like 10, 56, 88 etc. then 90 (this service) Start this service Start the service at this number. Means first start services with less number like 1, 5, 9 etc. then 10 (this service)

We use ntsysv, system-config-services or chkconfig commands to start or stop services at boot time. And change the default behavior of a run level.

Picture 1:


Changing The Default Runlevel: To change the default run level from 3 to 5. Open /etc/inittab file and do the following changes. vi /etc/inittab From: id:3:initdefault: To: id:5:initdefault: Save and exit and reboot system.

Linux Boot Process: Picture 2:

1. As explained in “picture 2� when we turn on computer system. First BIOS first does POST. 2. After POST BIOS checks first boot device in its configuration and tries to find boot loader program (a little program that loads operating system). Boot loader is divided in two parts. a. 1st stage boot loader: b. 2nd stage boot loader:

Points towards 2nd stage boot loader Gives boot menu and loads kernel of selected operating system and supports multi boot.

Because BIOS tries to find boot loader in MBR and MBR does not have much space to hold complete boot loader program. 3. 2nd stage boot loader then loads kernel. 4. Kernel starts init process (father of all processes in Linux systems, check with pstree command). 5. init process reads /etc/inittab file and find two things a. System initialization script (/etc/rc.d/rc.sysinit) b. Default run level


6. Init process executes /etc/rc.d/rc.sysinit 7. Then init process goes to default runlevel directory and start services. 8. Then system executes /etc/rc.d/rc.local file. Admin can write those commands in /etc/rc.d/rc.local file which he wants to execute every time system boots.

Concept of PATH: There are two PATH concepts in Linux/Unix 1. Directory Reach Path 2. Directory Search Path

Directory Reach Path: The way to reach/enter a particular directory or in command to specify that where a file or directory is present we use directory reach path. In windows we use to specify such path like this c:\programfiles etc. There are two types of Directory Reach Path in Linux: a. Absolute Path: b. Relative Path:

Starts from / Starts from current directory

Note: - A file or directory having “.” As first character in their names are hidden files/directories. - Whenever we create a directory two hidden directories are created “. “and “..” single dot represents current directory and .. represents parent directory. These hidden directories are created to keep relation between directories. These hidden files can be seen by “ls –l” command.

Picture 3: As described in “Picture 3” we want to change our present working directory from “sales” to “xyz” using absolute path to do so:

cd /test/xyz Absolute path starts from /, therefore we told system to go to / then go to test present in / and then go to xyz directory that is present in test directory. Now same change of directory but with Relative Path

cd ../../../test/xyz As relative path starts from current directory therefore, we told system to go in parent directory of the current directory (.. = mkt) then go parent of mkt directory (.. = docs) and then go in parent of doc directory (.. = / ) and then in / go test and then xyz directory.

Linux / Unix Commands:


Redhat Linux Command Prompt: Prompt is a place where we type commands. [root@LINUXBOX4 etc]# root: LINUXBOX4: etc:

represents user name Computer name / Host name Present working directory

Basic Structure of Unix/Linux Commands: [root@LINUXBOX4 root]#COMMAND [-options] [operand] …. [Operand] Command:

A command tells Linux/Unix system what task to do?

Options:

Options tells Linux/Unix system How to perform that task? There are two forms of options in which we write them in commands.

1. 2.

Long Form: Long form is written with “–-“ and after it complete name like --all Short Form: Short form is written with “-“ and after it a single letter of the word like–a

Operand:

Operand tells where OR on what entity, to do this task?

In Linux Unix command manuals What ever inside [ ] is optional. Therefore in general saying for all commands “Options” and Operands are optional part of a command they may or may not be present in a command. Example: [Root@LINUXBOX4 root]#ls ls command displays file and directories present in current directory [Root@LINUXBOX4 root]#ls –a -a is an option here tells Linux system to display files and directories and even display hidden files and directories. [root@LINUXBOX4 root]#ls –a /etc /etc is an operand here. Above command tells Linux system to display all (even hidden) file and directories of /etc. Means apply command on /etc. Some Commands: ls [-ailR] ls: displays file and directories present in current or specified directory -a: Tells ls to display all files and directories -i: Tells ls to display inode number with file name -l: Tells ls to display long/detailed list -R: Tells ls to display recursively contents of sub directories as well. cd cd:

cd is used to change working directory.

pwd pwd:

To check present working directory.

hostname hostname:

displays computer name.


whoami whoami:

displays that you are logged in with this name.

Wc wc: -w -l -c

[-lcw] is used to calculate words, lines and characters in a file. Tells wc to count words Tells wc to display number of lines in given a file. Tells wc to calculate number of characters in given a file.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.