22649807 linux lecture sem1
TRANSCRIPT
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 1/282
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 2/282
Operating Systems
Computers have two fundamentalcomponents:
Hardware: Physical components inside acomputer
Software: Set of instructions or programsthat understand how to use the hardware
of the computer in a meaningful way
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 3/282
3
Operating Systems (continued)
Hardware components include:Processor (CPU)
Physical memory (RAM)Hard disk, floppy disk, and CD-ROM
drives
Sound and video cards
Circuit boards
November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 4/282
4
Operating Systems (continued)
Two different types of programs are executedon a computer:Applications
Operating system (OS) softwareDevice Driver: Software containing instructions
that the OS uses to control and interact with aspecific type of computer hardware
User Interface: An application program thatallows the user to interact with the OS andother application programs
November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 5/282
5
Operating Systems (continued)Operating system: Software program
Set of instructions between hardware andsoftware
Way user communicates with computer
Processing of application programs
All input/output of computer
Controls/manages resources and users
November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 6/282
6
Operating Systems (continued)
The role of operating system software
November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 7/282
Unix/Linux History
Unix first version created in Bell Labs-1969
Write Unix system in C language-1973 by Denis Ritchie
AT&T licenses source code for low cost, Trademarkes Unixname, licensees must create new name for their operating
systems
Many Unix Flavors:, IBM-AIX, Solaris,UnixWare, HP-UX
7November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 8/282
Unix PrinciplesMultiuser, Multitasking
Configuration data stored in text
Ability to chain programs together toperform complex tasks
Working with Wide variety of
computersHigh Level of Security
8November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 9/282
GNU Project / FSF
GNU (Gnu Not Unix) Project startedin 1984 (R. Stallman)
Goal: create “free” Unix cloneBy 1990, nearly all required users
applications created (gcc, emacs,..)
Free Software FoundationNon-profit organization that managesGNU project
November 17, 2009 9
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 10/282
GPL- GNU General PublicLicense
Primary license for Open SourceSoftware
Encourages free softwareAll enhancements and changes to
GPL software must also be GPL
Often called “copyleft”“all rights reversed”
November 17, 2009 10
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 11/282
GPL- GNU General PublicLicense-2
freedom to run the program, for anypurpose.
freedom to modify the program tosuit your needs.freedom to redistribute copies, eithergratis or for a fee.
freedom to distribute modifiedversions of the program, so that thecommunity can benefit from yourimprovements
11November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 12/282
Linux OriginsLinus TorvaldsFinnish college student in 1991 create
Linux kernel
Code was made available over theinternet for freeCoders world wide took part in developing
the OS
When Linux Kernel combined withGNU applications, complete free Unix-like OS appears (GNU/Linux OS)
November 17, 2009 12
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 13/282
Why LinuxLinux and GNU software are distributed
under the terms of the GNU Public LicenseAgreement (GPL)
Linux is continually being developed byindividuals throughout the world
Skilled programmers can submit additionsand improvements to the Linux OS toLinux Development Team over the internet
November 17, 2009 13
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 14/282
Why LinuxApplications are developed that are
both free and commercialLinux is for Intel based platforms,
Power PC, Alpha-based Linux is forIntel based, multiprocessorcompatibility (SMPs)Fully supportedMany distribution
(redhat,suse,fedora,ubuntu ...)
14November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 15/282
Red Hat Enterprise Linux
Custom version of recent Linuxkernel
Utility and applicationsInstallation and configuration
software
Support available
15November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 16/282
Installing Red Hat LinuxPartitioning Hard disksPrimary Partition + Swap partition
Installation method
Network ConfigurationIP ,Netmask, Gateway, Hostname +Domain
name +Name Server
Configuring Boot manager (LILO, Grub)Select Package
November 17, 2009 16
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 17/282
Hard disk partitioning
hda: Primary Master IDE
hdb: Primary Slave IDE
hdc: Secondary Master IDE
hdd: Secondary Slave IDE
sda: First hard on SCSI bus (or SATA).
sdb: Second hard on SCSI bus (orSATA).
November 17, 2009 17
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 18/282
Hard disk partitioning-2Primary Partitions: 1,2,3,4
Logical Partitions: 5,6,7…
hdxy IDEsdxy SCSI, or SATAx (name of hard disk)
y (partition number )Example: hda2,hdb5,sda6
18November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 19/282
Hard disk partitioning-3
HeadHead
SectorSector
CylindersCylinders
Track Track
SectorsSectors
19November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 20/282
Hard disk partitioning-4
• Series of Sectors addressed by(CHS)
• First sector name MBR: MasterBoot Record contain:
• Boot program
• Partition Table:4 Primary partitions1 2 3 4
MBR Partition 1 Partition 3Partition 2 Partition 4
November 17, 2009 20
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 21/282
Hard disk partitioning-5
1 2 3 4
Primary
Partition 1
A 2 FAT32 2000
2001 FAT16 3500
3501 EXT2 6000
6001 NTFS 8000
Status Start FS End
0000
1BEh
1FEh
Partition
Table
Boot
Program
Primary
Partition 2
Primary
Partition 3
Primary
Partition 4
November 17, 2009 21
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 22/282
Hard disk partitioning-6
1 2 3 4
MBR
Boot Sectors
Primary
Partition 2
Primary
Partition 3
Primary
Partition 4
Primary
Partition 1
M
B
R
P. P. 1
Type: FAT32
P. P. 2
Type: Extended
P. P. 3
Type: Ext2
P. P. 4
Type: NTFS
November 17, 2009 22
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 23/282
Hard disk partitioning-7
M
B
R
D: E: F:C:
P1: FAT32 P2: Extended
MB
R
D: E: F:C:
P1: FAT32 P3: Extended
/ Swap
P2: EXT3
< 1024
23November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 24/282
Installing VMWare and using a
virtual machine to install Linux
24
Download VMWare(http://vmware.com/download/server/)
Apply for license keys(http://register.vmware.com/content/registration.html)
November 17, 2009
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 25/282
Begin the installation
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 26/282
Accept the license terms
November 17, 2009 26
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 27/282
Customize
November 17, 2009 27
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 28/282
Choose desired features andinstallation path
November 17, 2009 28
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 29/282
Disable AutoRun
Note: Windows XP requires extra steps here
November 17, 2009 29
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 30/282
Disable each auto-run type inXP
November 17, 2009 30
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 31/282
Ready to install!
November 17, 2009 31
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 32/282
This may take a while
Note: You may need to temporarily disable yourVirus Shield (mcsheild.exe hogs processor tickswhile VMWare installs)
November 17, 2009 32
Enter one of the serial number
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 33/282
Enter one of the serial numberyou applied for in the step
above.
November 17, 2009 33
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 34/282
Finished!
November 17, 2009 34
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 35/282
Connect to the new VMWareinstance
November 17, 2009 35
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 36/282
Check settings
November 17, 2009 36
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 37/282
Select a directory on a drivewith plenty of free space
November 17, 2009 37
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 38/282
Create a new virtual machine
November 17, 2009 38
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 39/282
Choose Linux
November 17, 2009 39
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 40/282
Give it a name
November 17, 2009 40
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 41/282
Using NAT is easiest
November 17, 2009 41
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 42/282
8 GB is plenty
November 17, 2009 42
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 43/282
VMWare will now create a newspace for the Virtual Machine
November 17, 2009 43
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 44/282
New Guest OS setup complete
November 17, 2009 44
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 45/282
Confirm NAT is selected
This works best, especially when the Host OS is using DHCPNovember 17, 2009 45
R d i ll OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 46/282
Ready to install OS
Insert your install CD (DVD) and start the virtual machine
November 17, 2009 46
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 47/282
Installation Mode
New or Upgrade
from whereCD
HTTP, FTP, NFS, Hard disk
Kickstart
47November 17, 2009
St ti th I t ll ti
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 48/282
48
Starting the Installation(continued)
Beginning a Red Hat installation
Linux-OS
St ti th I t ll ti
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 49/282
49
Starting the Installation(continued)
Press F2 at Welcome screen to getinstallation options
Check media for errors prior to installation
Optional, but recommended
Linux-OS
St ti th I t ll ti
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 50/282
50
Starting the Installation(continued)
Viewing installation options
Linux-OS
Ch i th L
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 51/282
51
Choosing the Language,Keyboard, Mouse, and Monitor
Keyboard model and layout automaticallydetected
Check “Emulate 3 Button” if mouse does
not have third buttonMost monitors automatically detectedIf not, try to locate on list of monitor models or
use generic model with correct horizontal andvertical sync
Incorrect monitor settings can damagemonitor
Linux-OS
K b d M d M it
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 52/282
52
,Keyboard, Mouse, and Monitor(continued)
Selecting an installation language
Linux-OS
K b d M d M it
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 53/282
53
,Keyboard, Mouse, and Monitor(continued)
Verifying keyboardconfiguration
Linux-OS
K b d M d M it
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 54/282
54
,Keyboard, Mouse, and Monitor(continued)
Figure 3-6: Selecting a mouse
type Linux-OS
,Ke board Mouse and Monitor
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 55/282
55
,Keyboard, Mouse, and Monitor(continued)
Verifying monitor configuration
Linux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 56/282
56
Specifying the Installation Type
Personal DesktopGUI environment and common applications
Workstation
Same as Personal Desktop plus administrativeand network tools
ServerSeveral server services
Custom
Linux-OS
Specifying the Installation Type
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 57/282
57
Specifying the Installation Type(continued)
Figure 3-8: Choosing an installation
type Linux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 58/282
58
Hard Disk Partitioning
Filesystems can be accessed if attached(mounted) to a directory
Minimum of two partitions
Partition for root directoryPartition for virtual memory (swap memory) Area on hard disk used to store information normally
residing in physical memory (RAM)
Automatic or manual partitioning
Linux-OS
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 59/282
59
Hard Disk Partitioning(continued)
Common Linux filesystems and sizes
Linux-OS
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 60/282
60
Hard Disk Partitioning(continued)
Figure 3-9: Choosing a disk partitioning
method Linux-OS
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 61/282
61
Hard Disk Partitioning(continued)
Different types of filesystemsExt2: Used on most Linux computers
Ext3: Performs journaling
Vfat: Compatible with Windows’ FAT filesystemREISER: Performs journaling
Journaling: Keeps track of the informationwritten to the hard drive
Disk Druid: Graphical partitioning program
Linux-OS
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 62/282
62
Hard Disk Partitioning(continued)
The Disk Druid partitioning utility
Linux-OS
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 63/282
63
Hard Disk Partitioning(continued)
Figure 3-11: Creating a newpartition
Linux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 64/282
64
Configuring the Boot Loader
Boot loader: Program started by BIOS ROMLoads kernel into memory
Can also boot other existing OSs
GRand Unified Bootloader (GRUB): Bootloader configured during Fedora Linuxinstallation
Dual booting: Choose OS to boot at startup
Linux-OS
Configuring the Boot Loader
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 65/282
65
Configuring the Boot Loader(continued)
Figure 3-12: Configuring a bootloader
Linux-OS
Configuring the Boot Loader
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 66/282
66
Configuring the Boot Loader(continued)
Boot loader usually resides on the MBR oron first sector of / or /boot partition
Kernel parameters: Information passed to
Linux kernel via the boot loaderLarge Block Addressing 32-bit (LBA32):
Enables Large Block Addressing in bootloaderFor large hard disks not fully supported by the
BIOS
Linux-OS
Configuring the Boot Loader
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 67/282
67
Configuring the Boot Loader(continued)
Configuring advanced boot loader options
Linux-OS
Configuring the Network and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 68/282
68
Configuring the Network andFirewall
Specifying a network configuration
Linux-OS
Configuring the Network and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 69/282
69
Configuring the Network andFirewall (continued)
Will NIC be activated at boot time?
Manual IP configurationSet IP address, Netmask, host name, gateway, primary
domain name space (DNS)
Automatic IP configuration via DHCP
Firewall prevents traffic from entering computerCustomize which traffic is allowed through
Linux-OS
Configuring the Network and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 70/282
70
Configuring the Network andFirewall (continued)
Configuring a firewall
Linux-OS
Choosing a System Language
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 71/282
71
Choosing a System Languageand Time Zone
Selecting additional language support
Linux-OS
Choosing a System Language
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 72/282
72
Choosing a System Languageand Time Zone (continued)
Choosing a time zone
Linux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 73/282
73
Creating the Root User
Authentication: Users log in via valid username and password
Configure two user accounts
Administrator account (root) Full rights to system
Regular user account
Linux-OS
Creating the Root User
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 74/282
74
Creating the Root User(continued)
Setting a root password
Linux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 75/282
75
Selecting Packages
Figure 3-19: Selecting
packages Linux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 76/282
76
Installing Packages
Figure 3-19: Package
InstallationLinux-OS
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 77/282
77
Completing the Firstboot Wizard
Complete the installationLicense agreement
Graphics settings
User accounts and authenticationInstall additional software
Log in with user account for daily tasks
Shadow password: stored in separate DB
from user accountsMD5: password encryption method
Linux-OS
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 78/282
78
Completing the Firstboot Wizard(continued)
Setting the date and time
Linux-OS
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 79/282
79
Completing the Firstboot Wizard(continued)
Configuring screen resolution and colordepth
Linux-OS
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 80/282
80
Completing the Firstboot Wizard(continued)
Creating a regular user account
Linux-OS
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 81/282
81
Completing the Firstboot Wizard(continued)
Configuring user informationLinux-OS
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 82/282
82
Completing the Firstboot Wizard(continued)
Configuring authentication
Linux-OS
Installing Linux: Installation
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 83/282
83
Installing Linux: InstallationMethods
FTP serverHTTP Web serverNFS server
Packages on hard diskBoot from first Red Hat (Fedora) Linux CD-
ROM
Performing the Installation: Starting
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 84/282
84
Performing the Installation: Startingthe Installation (continued)
Beginning a Red Hat installation
Performing the Installation: Starting
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 85/282
85
Performing the Installation: Startingthe Installation (continued)
Press F2 at Welcome screen to getinstallation options
Check media for errors prior to installation
Optional, but recommended
Choosing the Language Keyboard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 86/282
86
Choosing the Language, Keyboard,Mouse, and Monitor
Keyboard model and layoutautomatically detected
Check “Emulate 3 Button” if mouse
does not have third buttonMost monitors automatically detectedIf not, try to locate on list of monitor models
or use generic model with correct horizontaland vertical sync
Choosing the Language Keyboard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 87/282
87
Choosing the Language, Keyboard,Mouse, and Monitor (continued)
Selecting an installation language
Choosing the Language Keyboard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 88/282
88
Choosing the Language, Keyboard,Mouse, and Monitor (continued)
Verifying keyboard configuration
Choosing the Language Keyboard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 89/282
89
Choosing the Language, Keyboard,Mouse, and Monitor (continued)
Selecting a mouse type
Choosing the Language, Keyboard,
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 90/282
90
Choosing the Language, Keyboard,Mouse, and Monitor (continued)
Verifying monitor configuration
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 91/282
91
Specifying the Installation Type
Personal DesktopGUI environment and common applications
Workstation
Same as Personal Desktop plus administrativeand network tools
ServerSeveral server services
Custom
Specifying the Installation Type
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 92/282
92
Specifying the Installation Type(continued)
Choosing an installation type
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 93/282
93
Hard Disk Partitioning
Filesystems can be accessed if attached(mounted) to a directory
Minimum of two partitions
Partition for root directoryPartition for virtual memory (swap memory) Area on hard disk used to store information normally
residing in physical memory (RAM)
Automatic or manual partitioning
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 94/282
94
g(continued)
Common Linux filesystems and sizes
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 95/282
g(continued)
Choosing a disk partitioning method
Hard Disk Partitioning
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 96/282
96
g(continued)
The Disk Druid partitioning utility
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 97/282
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 98/282
98
Configuring the Boot Loader
Boot loader: Program started by BIOS ROMLoads kernel into memory
Can also boot other existing OSs
GRand Unified Bootloader (GRUB): Bootloader configured during Fedora Linuxinstallation
Dual booting: Choose OS to boot at startup
Configuring the Boot Loader
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 99/282
99
g g(continued)
Configuring a boot loader
Configuring the Boot Loader
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 100/282
100
g g(continued)
Boot loader usually resides on the MBR oron first sector of / or /boot partition
Kernel parameters: Information passed to
Linux kernel via the boot loaderLarge Block Addressing 32-bit (LBA32):
Enables Large Block Addressing in bootloaderFor large hard disks not fully supported by the
BIOS
Configuring the Boot Loader
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 101/282
101
g g(continued)
Configuring advanced boot loader options
Configuring the Network and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 102/282
102
Firewall
Specifying a network configuration
Configuring the Network and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 103/282
103
g gFirewall (continued)
Will NIC be activated at boot time?
Manual IP configurationSet IP address, Netmask, host name, gateway, primary
domain name space (DNS)
Automatic IP configuration via DHCP
Firewall prevents traffic from entering computerCustomize which traffic is allowed through
Configuring the Network and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 104/282
104
g gFirewall (continued)
Configuring a firewall
Choosing a System Language and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 105/282
105
g y g g Time Zone
Selecting additional language support
Choosing a System Language and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 106/282
106
g y g g Time Zone (continued)
Choosing a time zone
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 107/282
107
Creating the Root User
Authentication: Users log in via valid username and password
Configure two user accounts
Administrator account (root) Full rights to system
Regular user account
Creating the Root User
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 108/282
108
(continued)
Setting a root password
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 109/282
109
Selecting Packages
Selecting packages
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 110/282
110
Installing Packages
Package Installation
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 111/282
111
Completing the Firstboot Wizard
Complete the installationLicense agreement
Graphics settings
User accounts and authentication
Install additional software
Log in with user account for daily tasks
Shadow password: stored in separate DB
from user accountsMD5: password encryption method
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 112/282
112
(continued)
Setting the date and time
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 113/282
113
(continued)
Configuring screen resolution and color depth
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 114/282
114
(continued)
Creating a regular user account
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 115/282
115
(continued)
Configuring user information
Completing the Firstboot Wizard
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 116/282
116
(continued)
Configuring authentication
L l L i
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 117/282
Local Login
Text mode login at Virtual consolesMultiple non-GUI logins are possible through the
use of virtual consoles
There are by default 6 available virtual consolesAvailable through Ctrl-Alt-F[1-6]
Graphical loginIf X is running, it is available as Ctrl-Alt-F7
November 17, 2009 117
Li G hi l E i t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 118/282
Linux Graphical Environments
XFree86: standard X windows System
GNOME – Desktop environment based on the
GTK+ toolkitKDE – Desktop environment based on the Qt
toolkit
November 17, 2009 118
Shells, Terminals, and theK l
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 119/282
119
Kernel
Shells, terminals
C Li t i l
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 120/282
120
Common Linux terminals
R i C d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 121/282
121
Running Commands
Command-line terminal may be accessedfrom GUI environmentCommand prompt:
Root user: #Regular user: $
R i C d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 122/282
Running Commands
Command have the following syntax:command [options] [arguments]
Each item is separated by a space
Case sensitive
Options modify the command’s behavior
Arguments are filenames or otherinformation needed by the command
Separated commands with semicolon (;)Example: date;cal
November 17, 2009 122
Ch i Y P d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 123/282
Changing Your Password
Password should be changed after first login
From the Red Hat menu, choose
Preferances
PasswordFrom a terminal, use passwd
November 17, 2009 123
Shutting Down the LinuxS t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 124/282
124
System
Commands to halt and reboot the Linux operatingsystem
The Filesystem HierarchySt d d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 125/282
125
Standard
Filesystem Hierarchy Standard (FHS):Standard set of directories for Linux andUNIX systemsFile and subdirectory contents
Gives Linux software developers ability to locatefiles on any Linux system Create non-distribution–specific software
The Filesystem HierarchyStandard (continued)
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 126/282
126
Standard (continued)
: Linux directories defined by FHS
The Filesystem HierarchyStandard (continued)
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 127/282
127
Standard (continued)
Linux directories defined by FHS
Linux File HierarchyC t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 128/282
128
Concepts
The Windows filesystem structure
The Linux filesystem structure
Linux File Hierarchy Concepts
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 129/282
Linux File Hierarchy Concepts
November 17, 2009 129
Directories maycontain plain filesor other directories
Leads to a treestructure for thefilesystem
Root directory: /
/
tmpusersbin
doug rocket
cs2204joke.txt
lab2.txtlab1.txt
Listing Directory Contents
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 130/282
g yList the content of a current directory or a specified
directoryUsage:
ls [options] [files or dirs]
• Example:
• ls
• ls /home
• ls –l
• ls -a
130
The Home Directory
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 131/282
The Home Directory
Every user has a home directory, typically under/home
Contain user-specific configuration files as well asuser data
Represented by the ~ character
November 17, 2009 131
Absolute pathnames
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 132/282
Absolute pathnames
Absolute pathnames begin with a slash (/)
Complete “road map” to file location
Can be used anytime you wish to specify a filename
November 17, 2009 132
Relative pathnames
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 133/282
Relative pathnames
relative pathnames do not begin with a slash (/)
Specifies location relative to your current working
directory
Can be used as a shorter way to specify a file name
November 17, 2009 133
th
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 134/282
pathnames
November 17, 2009 134
Separate directories by /
Absolute path
start at root and followthe tree
e.g. /users/doug/joke.txtRelative path
start at workingdirectory
.. refers to level above;
. refers to working dir. If /users/doug/cs2204 is
working dir, this referto the same file asprevious one
joke.txt
/
tmpusersbin
doug rocket
cs2204
lab2.txtlab1.txt
Changing Directory
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 135/282
Changing Directory
pwd displays the absolute path to the currentdirectory
cd changes directories- To an absolute path: $ cd /home/issa/work
- To relative path:$ cd project/docs
- To a directory one level up: $ cd ..
- To your directory home: $ cd
- To your previous working directory: $ cd -
November 17, 2009 135
File names
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 136/282
File names
File names may be up to 255 charactersAll characters are valid, except the “/”It may be unwise to use certain special characters in
filename
File names are case-sensitiveExample: MAIL, Mail, mail, and mAil
Again, possible, but may not be wise
November 17, 2009 136
Getting Command Help
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 137/282
137
Getting Command Help
Linux distributions contain manycommands
Manual pages: Most common form of documentation for Linux commands“man” pages
At command prompt, type “man” followed by acommand name
Contain different sections
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 138/282
138
Manual page section numbers
Getting Command Help
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 139/282
Getting Command Help
Examples
man ls
man 5 passwd (5 for section)
man passwd
November 17, 2009 139
Other Help Utilities
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 140/282
Other Help Utilities
command --help The whatis same as man –f
The apropos same as man –k
info Text based with sections organized by subject Command is info section_name
Gnome documentation
November 17, 2009 140
Copying files and Directories
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 141/282
Copying files and Directories
cp – copy files and directoriesUsage:
cp [options] file destinationMore than one files may be copied at a time if the
destination is a directorycp [options] file1 file2 dest
November 17, 2009 141
Copying Files and Directories:Th D i i
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 142/282
The Destination
If the destination exists and is a directory, thecopy is placed there with the same name
If the destination exist and is a file, the copyoverwrites the destination file
If the destination does not exist, the copy iscreated with that name
142
Moving and Renaming
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 143/282
Files and Directories
mv – move and/or rename files and directories
Usage:
mv [options] file destination
More than one files may be moved at a time if thedestination is a directory
mv [options] file1 file2 dest
143
Moving and Renaming Files and
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 144/282
Directories: the Destination
If the destination exists and is a directory, the sourcefiles or directory is moved there with the same name
If the destination exist and is a file, the source file ismoved to that filename, overwriting the file
If the destination does not exist, the source file ordirectory is renamed with that name
144
Removing and Creating Files
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 145/282
Removing and Creating Files rm – remove files
Usage:
rm [options] filenames -i interactive
-r recursive (when removing directory) -f force
touch – create empty files or update filestamps
145
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 146/282
Determining File Content
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 147/282
Determining File Content
Files can contain many types of data
Check file type before opening to determineappropriate command or application to use
Syntaxfile [options] filename (s)
November 17, 2009 147
Viewing an Entire Text File
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 148/282
Viewing an Entire Text File
Syntax
cat [options] [file …]
Contents of the files are displayedsequentially with no break
Files display “concatenated”
November 17, 2009 148
Viewing Files One ScreenfulAt Ti
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 149/282
At a Time
Syntax
less [options] [filename]
Display the contents of a text file one screen at a time
less is the pager used by man Syntax
more [options] [filename]
November 17, 2009 149
bash Introduction
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 150/282
Bourne shell (sh) –original UNIX shell writtenby Steven Bourne at AT&T
bash “Bourne Again shell “ Developed forGNU project
bash The de facto standard Linux shell
Backward – compatible with Bourne shell (sh)– the original (standard) UNIX shell.
November 17, 2009 150
bash Heritage
C shell (csh) – written by bill joy at UC Berkeley
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 151/282
( ) y j y yAdded many features such as command completion,
history and job controlKorn shell (ksh) – written by David Korn at AT&T
Bourne Again Shell (bash) Implements many of the extra features found in csh, ksh
Command line completionCommand line editing
Command line history
Sophisticated prompt control
November 17, 2009 151
File GlobbingGlobbing is wildcard expansion:
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 152/282
g p * matches zero or more characters
? matches any single character [a-z] matches a range of characters
[^a-z] matches all except the range
Example
$ls /usr/bin/b*
$ls /usr/bin/?b*$ls a[0-9]
$ls [!Aa]*
152
The Tab key
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 153/282
The Tab key
Type <TAB> key to complete command line:For the command name, it will complete a command
name
For an argument, it will complete a file name
Examaple:slo<TAB>
slocate
ls myf<TAB>
November 17, 2009 153
history
b h t hi t f d ’ t d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 154/282
bash stores a history of commands you’ve entered,
which can be used to repeat commandsUse history command to see a list of
“remembered” commands: $ historyUse bang character !
!x execute last command begin with x!2 execute command no 2
!! Execute Last command
154
History-2
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 155/282
Use the up and down arrow keys to scrollthrough previous commands
Type <CTRL-R> to search for a commandin command history
(reverse-i-search)`’: To recall last argument from previous
command:
<ESC>. Or <ALT-.>
November 17, 2009 155
Command Editing Tricks
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 156/282
<Ctrl-a> move to beginning of line<Ctrl-e> move cursor to end of line
<Esc>f move cursor to beginning of next
word<Esc>b move cursor to beginning of
previous or current word
<Ctrl-u> delete to beginning of line
<Ctrl-k> delete to end of line
156
Command Editing Tricks
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 157/282
Editing Modes
By default, bash uses emacs-style keybindings for command editing
Type set –o vito change key bindings to vi-style
Make vi the default by adding the commandabove to $HOME/.inputrc
November 17, 2009 157
Tilde
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 158/282
Hidden file begin with . for listing them use ls -a Tilde (~)Refer to your home directory:
$ cat ~/.bashrc
May refer to another user’s home directory:$ ls ~issa/.bashrc
158
The bash Shell
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 159/282
Variable
A variable is a label that has a valueVariables are resident in memory
Tow types: local and environment
Local variables are used only by the shell
Environment variables are passed onto othercommands and shells.
set to display all variables env display environment variables
November 17, 2009 159
Local Variable
C i ll ll
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 160/282
Conventionally all upper-case
Setting variable value$ CREDIT=300
$ echo $CREDIT
Common Local VariablesHISTFILESIZE determine how many command to be
saved in the history file on logout
COLUMN sets the width of the terminal
LINES sets the height of terminalsPS1 sets the prompt
November 17, 2009 160
Environment variables
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 161/282
Shell variables exist only in current shellinstance
Environment variables passed to subshells
Shell variables can be exported intoenvironment
$ CREDIT=300; export CREDIT
November 17, 2009 161
Common Environment variables
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 162/282
HOME Path to user’s home directory
LANG Identification of default languageprogram should use
PWD User’s current working directory
EDITOR default editor program
LESS options to pass to the command less
TERM terminal type
November 17, 2009 162
Environment variables
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 163/282
PATH colon separated list of locations wherecommands can be found
which command (not variable) showing path
of executable$which ls
Path to command can also be given explicitly
$ /bin/ls /etc$ ./ls /etc
November 17, 2009 163
Aliases
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 164/282
Aliases
Aliases let you create shortcuts to command
$ Alias dir=‘ls –laF’
Use alias to see all set aliases To see alias value: $ alias dir
$ alias dir=‘ls –laF’
November 17, 2009 164
Variable and String
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 165/282
Parameter/Variable: $Substitute the value of variable in a command line
$ cat $HOME/.bash_profile
$ echo $PATH
Curly braces: { }A string is created for every pattern inside the braces
regardless if any file exist
$ rm hello.{c,o}
November 17, 2009 165
Command and Math
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 166/282
Command output: ` ` or $() substitute output from a command in a command line
$ echo “Hostname: `hostname`”
$ echo $(date)
Arithmetic: $[ ]Substitute result of arithmetic expression in a
command line
$ echo Area: $[ $x * $y ]
November 17, 2009 166
Protecting from Expansion:B k l h
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 167/282
BackslashBackslash ( \ ) is the escape character and makes
the next character literal
$ echo Your cost: \$5.00
Used as last character on line to continue commandon next line:
$ echo “This long string will be echoed \
back as one long line”
This long string will be echoed back as one longline”
November 17, 2009 167
Protecting from Expansion:Q
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 168/282
Quotes
Single quotes (‘) inhibit all expansion
Double quotes (“) inhibit all expansion except
$ (dollar sign) including $()
` (back tick), command substitution
\ (backslash),single character inhibition
! (exclamation point), history substitution
November 17, 2009 168
Shell Startup Script
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 169/282
November 17, 2009 169
Shell Startup Script
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 170/282
November 17, 2009 170
Startup Script: order of execution
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 171/282
November 17, 2009 171
/etc/profile
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 172/282
November 17, 2009 172
/etc/profile.d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 173/282
/etc/profile.d
November 17, 2009 173
~/.bash_profile and ~.bashrc
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 174/282
November 17, 2009 174
~/.bash_logout
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 175/282
November 17, 2009 175
Overview of vi and vim
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 176/282
Overview of vi and vim
vi: the “visual editor”, standard Linux andUnix editor
vim: the “vi improved” standard Red Hateditor
On Red hat operating systems, the vi command invokes vim
Derived from earlier Unix editorsed->ex->vi->vim
November 17, 2009 176
Starting of vi and vim
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 177/282
Starting of vi and vim
To start vim : vi filenameIf the file exists, the file is opened and the content
are displayed
If the file doesn’t exists, vi create it when theedits are saved for the first time
November 17, 2009 177
Three Modes of vi and vim
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 178/282
Command modeCursor movement
Change, delete, yank, put
Insert mode Type in new text
Return to command mode with <ESC>
Ex mode
Configuring, exiting, savingSearch and replace
November 17, 2009 178
Three Modes of vi and vim
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 179/282
Three Modes of vi and vim
November 17, 2009 179
command
mode
insert
mode
last line
Mode or Ex mode
iESC :
wrong command
Cursor MovementInsert mode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 180/282
Insert modeh left, j down , k up , l rightw word ahead, b word back
Arrow keys also work
a append after the cursor
i insert before the cursorA append to end of line
I insert at beginning of line
o open a line below
O open a line above
November 17, 2009 180
Command mode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 181/282
<esc> takes you from insert mode backto command mode
cc change line, dd delete line, yy yank(copy) line
cw change word, dw delete word, yw yank word
Use p or P to put (paste) copied or deleteddata
November 17, 2009 181
Undoing Changes
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 182/282
Undoing Changes
u undo most recent change
U undo all changes to current line since thecursor landed on the line
<Ctrl-r> redo last “undone” change
November 17, 2009 182
Searching for Text
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 183/282
Searching for Text
/text search downwards for “text”
?text search Upwards for “text”
n continue search in the same directionN continue search in the opposite direction
November 17, 2009 183
Saving and Exiting: ex mode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 184/282
:wq save changes
:q or q! abandon changes
:w save without exit
:e! abandon changes without exit
:wq! Forcing save changes
:w! Forcing save without exit
November 17, 2009 184
A few tricks
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 185/282
A few tricks5dd delete 5 line (a number can precede any
of the tow character change, delete, yank, orput command
x delete a characterrc replace a character with c
R replace character for character until
<esc>
November 17, 2009 185
Users
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 186/282
Every user of the system is assigned aunique User ID number
User’s names and uid are stored in
/etc/passwdUser are assigned a home directory and a
program that is run when they log in (usuallyshell)
Users cannot read, write or execute eachothers’ files without permission
November 17, 2009 186
Groups
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 187/282
p
User’s are assigned to groups with uniquegroup ID number (gid)
gids are stored in /etc/group
Each user is given their own private group They can also be added to other groups to gain
additional access
all users in a group can share files that
belong to the group
November 17, 2009 187
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 188/282
User and Group ID Numbers
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 189/282
User names map to user ID numbers
Group names map to group ID numbers
Data stored on the hard disk is stored numerically
Authentication information is stored in plain text files:/etc/passwd
/etc/shadow
/etc/group
November 17, 2009 189
System Users and Groups
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 190/282
Server programs such as web or printservers typically run as unprivileged users,not as root
Examples: mail, lp, nobodyRunning programs in this way limits the
amount of damage any single program cando to the system
November 17, 2009 190
Changing Your Identity
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 191/282
To change your password, run passwdInsecure passwords are rejected
To start a new shell as a different user:susu –
su username
su - username
November 17, 2009 191
The Linux Security Model
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 192/282
Users and groups are used to controlaccess to files and resources
Users log in to the system by supplying
their user name and passwordEvery file on the system is owned by auser and associated with a group
Every process has an owner and group
affiliation , and can only access theresources its owner or group can access
November 17, 2009 192
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 193/282
Linux Process Security
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 194/282
When a process accesses a file the userand group of the process are comparedwith the user and group of the fileIf the user matches, the user permissions apply
If the group matches, but the user doesn’t, thegroup permissions apply
If neither match, the other permission apply
November 17, 2009 194
Examining Permissions
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 195/282
File permissions may be viewed using ls$ ls –l /bin/login-rwxr-xr-x 1 root root 19080 Apr 1 18:26 /bin/login
File type and file access permission aresymbolized by a 10-character string
November 17, 2009 195
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 196/282
File Permission Types
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 197/282
Four symbols are used when displayingpermission:
r : permission to read a file or list a directory’scontentw : permission to write to a file or create and
remove files from a directory
x : permission to execute a program file orchange into a directory and do long listing of thedirectory
- : no permission (in place of the r, w, or x)
November 17, 2009 197
File Permission Types
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 198/282
November 17, 2009 198
Examining Directories
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 199/282
The first character in the long listingdistinguish directories (d) from regular files(-)
$ ls –ld /bindrwxr-xr-x 2 root root 4096 Apr 1 18:26 /bin
$ ls –l /bin/df -rwxr-xr-x 1 root root 4096 Apr 1 18:26 /bin/df
Others file types indicators exist
November 17, 2009 199
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 200/282
Examining group Permissions
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 201/282
Characters 5,6, and 7 in the access modeidentify group permissions
$ ls –l README-rw-rw-r-- 1 issa teachers 9080 Oct 1 8:26 README
This file can be read and written by
people in group teachers, but it cannot beexecuted.
November 17, 2009 201
Examining Other Permissions
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 202/282
Characters 8,9, and 10 in the access modeidentify permissions for others:
$ ls –l README-rw-rw-r-- 1 issa teachers 9080 Oct 1 8:26 README
This file can be read by people outsidegroup teachers, but it cannot be changed
or executed
November 17, 2009 202
Changing PermissionsSymbolic method
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 203/282
y
To change access mode :
$ chmod [-R] mode file…
Changes the access mode of files and directories
-R option: Change permission to directory and allfiles and subdirectory inside it content
November 17, 2009 203
Changing PermissionsSymbolic method
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 204/282
y
November 17, 2009 204
Examples: try this examplechmod u+x file (or dir) , chmod o-w file(or
dir)
chmod g+wx,o=r file (or dir)chmod u=rwx file (or dir)
Changing PermissionsNumeric method
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 205/282
Uses a three-digit mode numbersFirst digit specifies owner’s permission
Second digit specifies group permission
Third digit represents other’s permission
Permissions are calculated by adding :
November 17, 2009 205
Changing PermissionsNumeric method
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 206/282
Examples:chmod 755 file1 (dir1)
chmod 666 file1(dir1)
November 17, 2009 206
umaskOnly applies to newly created files and directories
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 207/282
Used to alter the permissions on all new files anddirectories by taking select default file and directorypermissions awayWill never be used to modify the permissions of existing files
and directories
Read and write for all is the default (666) for files and777 for directory
Non-privileged user’s umask is 0002 and the root’sumask is 0022
November 17, 2009 207
umask
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 208/282
Non-privileged user’s umask is 0002 andthe root’s umask is 0022File will have permissions of 664
Default Mode 666
umask -002New File Mode 664
November 17, 2009 208
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 209/282
209
Performing a umask 007 calculation
Special Permissions
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 210/282
Special permissions: a fourth permission set (inaddition to user/group/other), Applicable in fourcases:SUID (set user ID) for an executable, Processes are
granted access to system resources based on userwho owns the file.
SGID (set group ID) for and executable, Same withSUID except group is affected.
SGID a directory: Files created in that directory willhave their group set to the directory's group.
November 17, 2009 210
Special Permissions
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 211/282
The sticky bit was used on files in the pastto lock them in memory Today, the sticky bit performs a useful
function only on directories:
Sticky bit for a directory, If set on a directory,then a user may only delete files that he ownsor for which he has explicit write permissiongranted, even when he has write access to the
directory. (e.g. /tmp )
Special Permissions
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 212/282
November 17, 2009 212
Setting Special Permissions(continued)
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 213/282
213
Representing special permissions in the mode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 214/282
214
Numeric representation of regular and special
permissions
SUID Permissions(example)When you login, your login shell process’ values are your user
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 215/282
ID and group IDE.g., if you run passwd (owned by root), THE user ID is your ID, not
root; then how can it update /etc/passwd file owned by root ?
SUID bit enables this functionality
When an executable file with set user ID (SUID) permission is executed,command run with permission of the owner of the command, not
executor of the commandFile permission of /usr/bin/passwd is r-s--x—x
The SUID can only be applied to binary compiled programs
November 17, 2009 215
Files sytsems
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 216/282
Disk drives are divided into partitionsPartitions are formatted with filesystems
alloying users to store dataDefault filesystem: ext3, The Third Extended
Linux Filesystems
Other common filesystems: ext2 , msdos, FAT, NTFS Iso9660(typically used for CDs)
November 17, 2009 216
Files sytsems(continued)
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 217/282
217
Filesystem has three main structuralsections:Superblock: Contains general information
about the filesystem e.g., number of inodes and data blocks
Inode: Describes a file or directory
Data blocks: Data making up contents of a file
InodeAn inode tables contains a list of all files in an ext2 or ext3
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 218/282
filesystemAn inode (index nodes) is an entry in the table, containing
information about a file (the metadata), including:File type, permission, link count, UID, GID
The file’s size and various time stamps
Pointers to the file’s data blocks on disk
One inode is associated with each file.
The system uses inodes as the definition of a file.
November 17, 2009 218
Directory
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 219/282
The computer’s reference for a file is theinode number
The human way to reference a file is by
file nameA directory is a mapping between the
human name for the file and thecomputer’s inode number
November 17, 2009 219
5 apples
4 oranges7 home
2 .
cp and inode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 220/282
The cp command: allocates a free inode number, placing a new
entry in the inode table
Create a directory entry, referencing the file
human file name to the inode numberCopies data into new file
November 17, 2009 220
mv and inode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 221/282
If the destination of the mv command ison the same file system as the source, themv command:Creates a new directory entry, with the news
file nameDeletes the old directory entry with the old file
name
Has no impact on the inode table (except for a
time stamp) or the location of the data on thedisk: no data is moved!
November 17, 2009 221
rm and inode
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 222/282
The rm command:Decrement the link count, thus freeing the
inode number to be reused
Places data bocks on the free list
Removed the directory entry
Data is not actually removed, but will beoverwritten when the data blocks are used
by another file
November 17, 2009 222
Linking Files
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 223/282
223
Symbolic link: One file is a pointer orshortcut to another
Hard link: Two files share the same data
Symbolic (or Soft) links
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 224/282
ls –i for displaying inode numberA symbolic link point to another file
ls –l display the link name and the
referenced file$ ls –l pf lrwxrwxrwx 1 issa issa 11 Oct 1 8:26 ps/etc/passwd
File type: l for symbolic link
Syntax
ln –s filename [linkname]
November 17, 2009 224
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 225/282
225
The structure of symbolically linked files
Hard linksDo not work with networked file systems, any
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 226/282
Do not work with networked file systems, anymounted devices, or any other file system
Only exist on same disk and partition as originalfile
One physical file on the filesystemEach link references the file’s inode
File is present in the filesystem as long as atleast one link remain
Syntaxln filename [linkname]
November 17, 2009 226
Hard links
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 227/282
To see which files are linked—check inodenumbers
Two files with same inode numbers—identical files
Any changes made to one file - reflected insecond file (true because files are linked)
To create links to files in differentdirectories first give read, write, andexecute permissions to other users
November 17, 2009 227
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 228/282
The structure of hard linked files
locate Command
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 229/282
Fastest way to search for file/s in entiredirectory tree locate looks in pre-defined database
Wildcards can be used with locate command
If database not updated cannot locatefiles even if files are in system
find command
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 230/282
find commandLocates specific file or group of files Does not rely on a database Searches directory tree for files
meeting criteria specifiedSearches recursivelyWildcards can be used in filename
statement
Ch 2 230
find command
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 231/282
Syntaxfind <dirs> [conditions] [action]
Recurses down in file tree in dirs
Optionally executes command oneach line of output
<Ctrl> + C is quick way to break
into command and stop it fromexecuting
November 17, 2009 231
some find options
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 232/282
Ch 2 232
Finding Examples
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 233/282
Example:find . -printfind all files in the current directory (and all
subdirectories) & display the results
find . -name “*.c” -printfind all files in the current directory (and all
subdirectories) with the extension .c & displaythe results
November 17, 2009 233
Finding Examples
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 234/282
find / -name myfile -print This command tells the find command to
look inside the / directory and everysubdirectory to look for a file or directorywith the name myfile and to display each
match it finds
find . -name “foo*” -amin -10 -print This command tells the find command to
look inside the current directory and everysubdirectory to look for a file with namebegin with foo that have been accessed inthe last 10 minutes and to display eachmatch it finds
Finding and processing Files
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 235/282
-exec action execute a command Syntax
find <dirs> [conditions] -exec cmd {} \;
“Found” files are passed to cmd as arguments{} is a place holder for the filename
The escaped semicolon delimit the generatedcommands
Finding Examples
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 236/282
Example: (for student)
find . -size +5000k
find . -name "*.tmp" -exec rm {} \;
November 17, 2009 236
whereis Command
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 237/282
ls, locate, and find commandsused to locate files of interest
whereis commandlocates/displays locations of aprogram, source, and manual pagesfor a specific command
Ch 2 237
whereis Command
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 238/282
whereis command
Faster than find command since
search path is built in More specific than locate command Searching for files that are
programs
whereis
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 239/282
KEY CONCEPTS: Most binary Command programs
located in the /usr/bin directory Most documentation located in
/usr/share/man directory Cannot execute a command unless it
is in your search path
Must have permission to execute acommand
File Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 240/282
Results in smaller file size
Text files can be compressed up to75%
Binary files usually don’t compressmuch
File Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 241/282
gzip Compresses a file or files Compressed file renamed filename.gz Syntax: gzip [options] [files]See option: –l -d
gunzip Uncompresses a file or files
Takes all of gzip’s options Syntax: gunzip [options] [files]
File Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 242/282
bzip2 Compresses file/files Compressed file renamed to filename.bz2
Syntax: bzip2 [options] [filenames . . . ]
bunzip2 Used to uncompress file/files Syntax: bunzip2 [options] [filenames . . .]
File Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 243/282
zcatReads compressed files compressed
with gzip and writes them to
standard output Identical to gunzip –c
Syntax: zcat [options] [files]
File Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 244/282
Sample compression commands (forstudent)
gzip termcapgzip -v termcap
gunzip -c termcap.gz | wc –l
gunzip termcap
November 17, 2009 244
File Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 245/282
KEY CONCEPTS: file no longer exist in home directory with
original name To see size of file when uncompressed pipe
output from zcat to wc commandFile seen in red—compressed/archived file Can see contents of .gz file (must be text
file) with zcat command
Archiving Tools
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 246/282
Tape archive (tar) utility: One of oldest andmost common backup utilitiesCan create archive in a file on a filesystem or
directly on a device
Accepts options to determine location of archiveand action to perform on archive
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 247/282
Archiving Tools
S
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 248/282
Syntax:tar [options] [tarfile] [other-files]
tar cvf archive_name filesc create a new archive
v produce verbose messages
f archive_name is the name of new file
Options do need a leading dash
November 17, 2009 248
Inspecting Archives
S t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 249/282
Syntax
tar tf archive_name.tar
tar tvf archive_name.tar
First form display a list of all files in the archive
The v cause a long listing of each file in the
archive
November 17, 2009 249
Extracting an Archive
S t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 250/282
Syntax
tar xvf archive_name.tar
The archive will be extracted in the current
directoryChange to the target directory first
Files maintain their hierarchy relative tothe current directory
Compressing archives
Oft t hi
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 251/282
Often tar archive are compress
tar can compress/uncompress archives
Compression switches- use during creation
and extraction z for gzip compression
j for bzip2 compression
November 17, 2009 251
tar with Compression
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 252/282
November 17, 2009 252
file1
sub-
directory
.tar .tar.gz
tar gzip
tar to Unformatted Floppies
Fl i d lik t d i
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 253/282
Floppies can used like tape drivesLow level format required
File system not needed
Use tar to write to the floppy/dev/fd0 is the destination
Floppy cannot be mounted
Example:
$ tar czvf /dev/fd0 mydir
November 17, 2009 253
Standard Input and Output
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 254/282
Linux provides three I/O channel toprocesses
Standard input (0): keyboard is defaultStandard output (1): terminal windows is
default
Standard error (2) : terminal windows is default
Redirecting Input and Output
d d i d b
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 255/282
standard input, output, and error can bereconnected to alternate locationsShell redirection operators allow standard I/O
channels to be redirected to/from a filePipes allow standard I/O channels to connected
to the input or output of programs
Redirecting Output
d d di i d d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 256/282
In order to study redirecting standardoutput, and error, we will use the find command.
find /etc –name passwd This command will search for all files
named passwd in /etc and its subdirectory
By default both the standard output andstandard error are displayed on the screen.
November 17, 2009 256
Redirecting Standard Output
R di ti t d d t t ith
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 257/282
Redirecting standard output with >find /etc –name passwd > findresult
standard error is still displayed on the screen.
If the target file of file redirection with >already exists, the existing file will beoverwritten
To append data to an existing file, use >> to
redirect instead of >
November 17, 2009 257
Redirecting Input and Output
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 258/282
Redirecting Standard Error
R di t t d d ith 2
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 259/282
Redirect standard error with 2>
Example : redirect standard error to a file:find /etc –name passwd 2> finderrors
Standard outputs still displayed on thescreen.
To append data to an existing file, use 2>>to redirect instead of 2>
November 17, 2009 259
Redirecting Standard Error
Can redirect standard error to a
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 260/282
Can redirect standard error to adevice called /dev/null
Example: Redirecting error
message in find command
find / -iname gedit 2> /dev/null
November 17, 2009 260
Redirecting Both StandardOutput and Error
Redirection of standard output and standard error
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 261/282
Redirection of standard output and standard errorcan be performed simultaneouslyfind /etc –name passwd 2> error > result
Each I/O channel can be redirected to different files,or the same file: find /etc –name passwd > alloutput 2>&1
Or find /etc –name passwd &> alloutput
November 17, 2009 261
Redirecting Input
Redirect standard Input with <
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 262/282
Redirect standard Input with <Some commands only operate on standard inputtr doesn’t accept filenames as arguments- it require its
input to be redirected from somewhere
tr ‘A-Z’ ‘a-z’ < .bash_profile This command will translate the uppercase character in
bash_profile to lowercase
November 17, 2009 262
Using pipes To connectprocesses
Pipes (the | character) let you redirect output
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 263/282
Pipes (the | character) let you redirect outputfrom one command to become input to anothercommandls /usr/lib | less
The mail command takes the message contentsas standard inputls –l | mail –s “here the listing” issa
November 17, 2009 263
tee
Let you tee a pipe: redirect output to a file
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 264/282
Let you tee a pipe: redirect output to a filewhile still piping it to another program
set | tee set.out | lessOutput from set command is written to file
set.out while also being piped to less
November 17, 2009 264
teeLet writing to output and simultaneously date | tee file1 file2
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 265/282
date | tee file1 file2
Thu Jun 10 11:10:34 CEST 2007 cat file1
Thu Jun 10 11:10:34 CEST 2007cat file2
Thu Jun 10 11:10:34 CEST 2007uptime | tee -a file2
11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26cat file2
Thu Jun 10 11:10:34 CEST 2007
11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26
String Processing Toolshead
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 266/282
head command display first few line (default : 10lines) of text in a filehead /tmp/output.txt
Use –n or --lines parameter to change numberof line displayedhead –n 20 /tmp/output.txt
266
String Processing Toolstail
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 267/282
tail command display last few line (default : 10 lines) of text in a filetail /etc/passwd
Use –n or --lines parameter to change number of line
displayedtail –n 5 /etc/passwd
Use –f to follow the end of a text file as it changestail –f 5 make.out
Used to watch log files
267
String Processing Toolswc
“ d t” l t li d h t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 268/282
“word count” – also counts lines and characterswc story.txt
39 237 1901 story.txt
Use –l for only line count
Use –w for only word count
Use –c for only character count
268
String Processing Toolssort
S i i l fil h d
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 269/282
Sort text to stout –original file unchanged
sort [option] file(s)
Common option:
-r Reverse sort to sort descending
-n Numeric sort
-f Ignore case of characters in strings
-u unique (remove duplicate lines in output)
-t ‘x’ Use x as field separator
-k pos1 sort from field pos1
269
String Processing Toolssort
$ cat b
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 270/282
$ cat bfishdoganimalbird
$ sort -r bfishdogbirdanimal
270
String Processing Toolssort
S t i fil t t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 271/282
Sort numeric file as text$ cat c5412 this line should go last
998 this line should go second
50 this line should go first
999 this line should go third
$ sort c50 this line should go first
5412 this line should go last
998 this line should go second
999 this line should go third
271
String Processing Toolssort
Sort numeric file as numbers
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 272/282
Sort numeric file as numbers$ cat c5412 this line should go last
998 this line should go second
50 this line should go first
999 this line should go third
$ sort -n c50 this line should go first
998 this line should go second
999 this line should go third
5412 this line should go last
272
String Processing Toolsuniq
R i d li li i fil
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 273/282
Remove successive, duplicate lines in a file
Can use in conjunction with sort to remove allduplicated (or use sort –u)
Use –c to count number of occurrences of duplicate data
273
String Processing Toolsuniq
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 274/282
274
Just sorted:
$ cat a | sort
birdbird
dog
dog
fish
fishfly
sort | uniq:
$ cat a | sort | uniq
birddog
fish
fly
String Processing Toolscut
Di l ifi l f fil d t
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 275/282
Display specific column of file data
cut –f4 result.dat
Common option:-f Specifies field or column
-d Specifies field delimiter (default is TAB)
cut –f3 –d: /etc/passwd
-c Cuts by characterscut –c2-5 /usr/share/dict/words
275
String Processing Toolscut
Example output second word on each
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 276/282
Example – output second word on eachline:Delimiter: space “ “
Fields: 2$ cat athe quick brown fox
jumped over a quick brown fox
$ cut -f 2 -d ' ' aquick
over
276
String Processing Toolscut
Example – output characters 1-3 5 7-end
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 277/282
Example output characters 1 3, 5, 7 end$ cat a
the quick brown fox
jumped over a quick brown fox
$ cut -c 1-3,5,7- atheqick brown fox
jume over a quick brown fox
Example for student:cut –f1 -d: /etc/passwd | sort -r | less
277
String Processing Tools
tr
tr command:
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 278/282
tr command: Translates and/or deletes characters from
standard input, writing to standard output Takes input only from standard input
Syntax is tr [options] string1 [string2]Example:tr ‘A-Z’ ‘a-z’ < .bash_profile
This command will translate the uppercase
character in bash_profile to lowercase
278
String Processing Toolspaste
t li f fil
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 279/282
paste - merge line of files
Syntax:Paste file1 file2
Most useful when combining files withcolumns of information
279
Version Comparison withdiff
Compares two files for differences
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 280/282
Compares two files for differences
diff area.c /tmp/area.c
33c33
< x = y + 2;----
> x = y +4;33c33 indicated line where files differ
< indicates line in first file> indicates line in second file
280
Formatting aDocument with pr
pr utility program: Converts text files into a paginated
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 281/282
pr utility program: Converts text files into a paginated,columned version If no files specified, pr read standard
input By default, pr formats files into single-
column pages of 66 lines To print in formatted form—pipe
formatted document to lpr Syntax: pr [options] [arguments]
Ch 7 281
Formatting aDocument with pr
8/8/2019 22649807 Linux Lecture Sem1
http://slidepdf.com/reader/full/22649807-linux-lecture-sem1 282/282