Linux

42
LINUX Presentation by Kallam Srinivas Reddy

description

Complete Linux Tutorial

Transcript of Linux

Page 1: Linux

LINUXPresentation by Kallam Srinivas Reddy

Page 2: Linux

Outline• Overview of Linux System• Vi editor• Basic Commands• Redirect, Append, and Pipe• Relative & Absolute Path• File System & Partitions• Permissions• Process Management• User Management• Group• Software Management• Backup and restore• Managing installed services

Page 3: Linux

Overview of Linux System

Linux is an Operating system (OS).Linux system is described as kernel & shell.Kernel is the main program of Linux system. It controls hardware,

CPU, memory, hard disk, network card etc.Shell is an interface between user and kernel. Shell interprets your

input as commands and pass them to kernel.

Page 4: Linux

Overview of Linux System

Multiuser & Multiprocess:Many people can use one machine at the same time.

File & Process:Data, directory, process, hard disk etc (almost everything) are

expressed as a file.Process is an running program identified by a unique id (PID).

Page 5: Linux

Overview of Linux System

Directory StructureFiles are put in a directory.All directories are in a hierarchical structure (tree structure).User can create and remove any directories on the tree.Top directory is “/”, which is called slash or root.Users have the own directory. (home directory)

Page 6: Linux

Overview of Linux System

Directory Structure

Page 7: Linux

Overview of Linux System

Important Directories:-/bin- This contains files that are essential for correct operation of the system. These are available for all users to use./mnt- Provides a location for mounting devices, such as remote file systems and removable media/home- This is where user home directories are stored./var- This directory is used to store files which change frequently, and must be available to be written to./etc- Various system configuration files are stored here.

Page 8: Linux

Overview of Linux System

/dev- This contains various devices as files, e.g. harddisk, CDROM drive, etc./root- This is the root (administrator) user's home directory/sbin- Binaries which are only expected to be used by the super user./tmp- Temporary files./boot Has the bootable Linux kernel and bootloader configuration files(GRUB)/usr- Contains user documentation, games, graphical files, libraries(lib),etc..

Page 9: Linux

Overview of Linux System

Normal user and Super userIn Linux system, there is one special user for administration, who can

do anything. This special user is called root or superuser.

Case SensitivityLinux operating system is case sensitive.

Page 10: Linux

Overview of Linux System

Run levels in Linux- refers to the mode of operation in the Linux operating systems

Following are the run levels of some popular Linux versionsFollowing are the seven run levels in Ubuntu

0 ->halt 1 ->Single user mode 2 ->Graphical multi-user with networking3 – 5 -> Unused but configured the same as runlevel 26 -> Reboot

Page 11: Linux

Overview of Linux System

Following are the seven run levels in Red Hat Linux and Fedora 0 ->halt 1 ->Single user text mode(without networking) 2 ->Not used (user definable) 3 -> Full multi-user text mode 4 -> Not used (user definable) 5 -> Full multi-user graphical mode (with an X-based login screen) 6 -> Reboot

Page 12: Linux

VI Editor

• Programs & configuration files are text files.• There are two popular text editors vi and Emacs.• vi is a screen-oriented text editor originally created for

the Unix operating system.

Page 13: Linux

Basic Commands

How to run commandsWhen you log on Linux machine, you will see, [cseos@hyperion001 srinu]$ start typing the command next to the $ symbol One command consists of three parts, i.e. command name, options,

arguments.Between command name, options and arguments, space is necessary.For Example [srinu~]$ command-name optionA optionB argument1 argument2

Page 14: Linux

Basic Commands

Options always start with “ - ”.For Example• cd ..• ls –l .bashrc• mv fileA fileB

Page 15: Linux

Basic Commands

Basic useful Commands ls - show files in current position cd - change directory cp - copy file or directory mv - move file or directory rm - remove file or directory pwd - show current position mkdir - create directory rmdir - remove directory cat - display file contentsless - display file contents pagewise

Page 16: Linux

Basic Commands

man - display online manualsu - switch user passwd - change password useradd - create new user account userdel - delete user account mount - mount a file system umount - unmount a mounted file system df - show disk space usage shutdown - reboot or turn off machine

Page 17: Linux

Redirect, Append and Pipe

Redirect and append Output of command is displayed on screen by redirecting to a file. Using “>”, you can redirect the output from screen to a file. Using “>>” you can append the output to the bottom of the file.Pipe Some commands require input from a file or other commands. Using “|”, you can use output from other command as input to the

command.

Page 18: Linux

Redirect, Append and Pipe

Commandshead - show first several lines and omit other lines.tail - show last several lines and omit other lines.grep - show lines matching a patternWorking with commands:In home directory, type ->ls .bash_profile

->cp .bash_profile sample.txt->less sample.txt

Page 19: Linux

Redirect, Append and Pipe

Using redirect.->head 3 sample.txt ->head 3 sample.txt > redirect.txt

Using append.->tail 3 sample.txt tail 3->sample.txt >> redirect.txt less redirect.txt

Using pipe.less redirect.txt grep PATH redirect.txttail redirect.txt | grep PATHrm sample.txtrm redirect.txt

Page 20: Linux

Relative & Absolute Path

Path means a position in the directory tree. To express a path, you can use relative path or absolute path.In relative path expression, the path is not defined uniquely, it

depends on your current path. In absolute path expression, the path is defined uniquely, it does not

depend on your current path.

Page 21: Linux

File System & Partitions

Everything is a file in linux.Mounting

Files related to mounting in linux/etc/mtab(Current files mounted)/etc/fstab(info about permanent mounting points)

Page 22: Linux

File System & Partitions

PartitionsCommands to view existing partitions

fdisk –l parted –l

Partition administration using fdiskfdisk <partition name with location> eg:- fdisk /dev/sda.Various options for fdisk are n,p,q,t,v,w,etc..Updating the partition without restarting :- partrobe /dev/sda or partx /dev/sda

Formatting a partition with file systems(eg- ext4 system)mkfs.<file system type> <partition name>Eg - mkfs.ext4 /dev/sda

Note:-After formatting the partition must me mounted in ordered to use

Page 23: Linux

File System & PartitionsMounting Partitions:-

Temporary mountingmount <device name> <directory name(mount point)>Eg:- mount /dev/sda oslab

Permanent mountingAdd the parameters for mounting point in the file /etc/fstab as follows

Device name Mount point type of fs mount options D CSUmounting the partition

umount <mount point directory>Eg:- umount /oslab

To view mount points use the command mountAssigning label to the partition(giving some name to partition)

e2label <partition name> <label>Eg:- e2label </dev/sda> <os>

Page 24: Linux

File System & Partitions

Mounting a partition using labelmount LABEL=<label name> <partition name>Eg:- mount LABEL=os /oslab

LVM(Logical volume management)

Page 25: Linux

File System & Partitions

Components of LVMPhysical volume (PV)Physical Extend (PE)Volume Group (VG)Logical Volume (LV)Logical Extend (LE)

Commands in LVMpvs, vgs, lvs – displays all PVs, VGs, and LVs in the system

Display detailed informationpvdisplay, vgdisplay, lvdisplay

creating PVs, VGs, LVspvcreate, vgcreate, and lvcreate

Page 26: Linux

File System & Partitions

lvresize – resizes a logical volumelvreduce – reduces a logical volumevgreduce – reduces a volume groupRemoving/deleting PVs, VGs, LVs

pvremove, vgremove, lvremove

Page 27: Linux

Permissions

All the files and directories have the permissions and owner assigned to them.

There are three types of permission readable, writeable and executable.Permissions are given to three kinds of groups namely owner, group

member and others.Example-

[cswug@hyperion001 cswug]$ ls l .bash_profile-rw-r--r-- 1 cswug cswug 191 Jan 4 13:11 .bash_profile

Note-r : readable, w:writable, x: executable

Page 28: Linux

Permissions

Commands-chmod- change file mode, add or remove permissionchown- change owner of the fileExample-chmod a+w filename - add writable permission to all userschmod o-x filename - remove executable permission from othersNote- u: user (owner), g: group, o: others a: all

Page 29: Linux

Permissions

acl- access control listsMore secure way to secure the files.The file system have to be mounted with the option acl in /etc/fstab

file.Files with acls can be read only using the getfacl command.Writing or changing acls can be done with setfacl or /usr/bin/setfacl.To remove an acl of a file system use –x option for setfacl command.

Page 30: Linux

Process Management

Process is a unit of running program.Each process has some information, like process ID, owner, priority, etc.Commands-Kill - Sends specified signal to specified process .The process is specified byprocess ID.Killall – kills all the process with a particular name. The program is specified

by command name.ps - Show process statustop - Show system usage statistics

Page 31: Linux

Process Management

Check your process.psps –u

Check process of all users.top (To quit top, press “q”)ps –eps –ef

Find your process.ps –ef | grep cseos

Page 32: Linux

Process Management

Output of “ top” command

Page 33: Linux

User Management

Commands to know whoami – Gives the current Username. who – gives the information about who is logged on the system. who am i – gives the details about current session in a line. w – shows you who is logged on and what they are doing. id – gives the user id, primary group id, and a list of the groups that

you belong to.

Page 34: Linux

User Management

Root user-The root user is also called the superuser is the most powerful account on the Linux system(userid 0)User management on any Unix can be done in three ways.1. Graphical2. Command line tools3. Edit the local configuration files

Page 35: Linux

User Management

Important files in user management-/etc/shadow- User passwords are encrypted and kept in /etc/shadow/etc/passwd –Contains the local user database on Linux/etc/default/useradd - contains some default user options.Home directories(Two ways of creating home directories)1. useradd –m to create a home directory for user.2. Create a directory using mkdir and setting the owner as user using

chmod and restricting the permissions.

Page 36: Linux

User Management

Commands for user managementuseradd- to add a userusermod – to modify the properties of a usergpasswd – to manage the usersuserdel – to delete a userpasswd – to manage passwords for users).chage – to change the attributes of the passwords of userssu – allows a user to run a shell of other usersSudo-The sudo program allows a user to start a program with the credentials of another user.

Page 37: Linux

Group

Users can be listed in groups.Groups allows you to set permissions on the group level instead of having to

set permissions for every individual user./etc/group – file in which group membership is defined.

Commands for group managementgroup – to view the list of groups to which user belongs to.groupadd – to add new groupsusermod - Group membership can be modifiedgroupmod – to change the group namegroupdel – to remove a group permanently

Page 38: Linux

Software Management

RPM utility is used to manage soft wares in linuxRPM – Red Hat Package Manager

Tool used for installing, uninstalling, verifying, querying, and updating software packages.

Commands for RPM rpm –qa (q- query and a- all) > gives all the installed packages on the system rpm –q <package name> > to check whether a package is installed or not. rpm –ivh <package name> > to install a package(i-install, v- verbose view, h-

hash progress) Note:- to install a package, first navigate to the directory in which packages are stored rpm –e <package name> >to uninstall/ remove a package(e- erase)

Page 39: Linux

Software Management rpm –qf <package directory> > to install the package forcefully rpm –qlc <packager name> > to see the configuration files of installed

package(q-query, l-local, c-configuration) rpm –qld <package name> > to see which directory is associated with a

particular package (q-query, l- local, d- directory)Dependency- some packages requires some other packages to be installed

before it can be installed. rpm -ivh <package name> --nodeps > to install packages without dependicies. rpm -uvh <package name> > to update a package(u- update, v-verbose, h-hash

progress)

Page 40: Linux

Backup and restoreBackup using tar

tar – cvf <destination and name to be> <source file> >creating a tar backup for source file (note: c-create, v-verbose, f-name of tar file)

eg:- tar – cvf /opt/etc.tar /etc gzip <file name> >applying gzip on the tar file eg:- gzip /opt/etc.tar scp <gzip file> <destination address> > transferring the file to another system

using secure copy (scr) (destination address is the IP address of the target system followed by the target directory)

eg:- scp /opt/etc.tar.gz 192.XXX.XX.X/root/ gunzip <file name> > to unzip the file tar – xvf <file name> > to untar the file (x-remove) eg:- tar – xvf etc.tar

Page 41: Linux

Managing installed servicesServices/programsTwo commands to control the services

1. Service Temporary control(changes only for current session / after booting the

changes will be erased from the service)Commands

service <name of the service> status -> used to check the status of the serviceservice <name of the service> start -> used to start the serviceservice <name of the service> stop -> used to stop the serviceservice <name of the service> reload -> used to reload the serviceservice <name of the service> restart -> used to restart the service

Page 42: Linux

Managing installed services

2. ChkconfigPermanent control(changes are carried until they are changed again no

matter of booting).Commands

chkconfig - - list >to check the availability of the servicechkconfig <service> on > to make the service available after restart chkconfig <service> off > to make the service unavailable after restart