Linux
-
Upload
srinivas-reddy -
Category
Technology
-
view
139 -
download
0
Transcript of Linux
LINUXPresentation by Kallam Srinivas Reddy
(K00316758)Operating Systems CSEN5322_002_201410
Instructor- Young lee
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
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.
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).
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)
Overview of Linux System
Directory Structure
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.
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..
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.
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
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
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.
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
Basic Commands
Options always start with “ - ”.For Example• cd ..• ls –l .bashrc• mv fileA fileB
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
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
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.
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
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
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.
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)
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
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>
File System & Partitions
Mounting a partition using labelmount LABEL=<label name> <partition name>Eg:- mount LABEL=os /oslab
LVM(Logical volume management)
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
File System & Partitions
lvresize – resizes a logical volumelvreduce – reduces a logical volumevgreduce – reduces a volume groupRemoving/deleting PVs, VGs, LVs
pvremove, vgremove, lvremove
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
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
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.
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
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
Process Management
Output of “ top” command
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.
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
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.
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.
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
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)
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)
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
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
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