linux unix day 2
TRANSCRIPT
-
8/2/2019 Linux Unix Day 2
1/64
Linux File system
-
8/2/2019 Linux Unix Day 2
2/64
Linux File system
Super block: The superblock contains information about the
filesystem as a whole, such as its size
Inode block: Contains all information about a file, except its name.Also includes the number for data blocks for that block.
Data block: Used to store data in the file.
Directory block: A directory entry consists of a filename and the
number of the inode which represents the file.
Indirection block: These dynamically allocated blocks are indirect
blocks; the name indicates that in order to find the data block, onehas to find its number in the indirect block first.
-
8/2/2019 Linux Unix Day 2
3/64
Directories
/
etc home bin usr lib
dev boot/ - first of mount point in linux
/etc - keep linux default configuration/boot - keep important linux booting files
/dev - keep all device files
/usr - keep all user binary and X library/home - keep user home directory
/var - keeping mail, log file and printer spooling
-
8/2/2019 Linux Unix Day 2
4/64
Directories
Directory
Used to organize other files into a logical tree structure
Absolute pathname
Pathname from the root directory to a certain file or
directory
Root
The top level directory
Referred to using the / character
-
8/2/2019 Linux Unix Day 2
5/64
Directories
~ metacharacter
Can be used to refer to the current users
home directory
Can be used to specify another users homedirectory by appending a username at the
end of the ~ metacharacter
Relative pathname
Pathname of a target directory relative to your
current directory in the tree
-
8/2/2019 Linux Unix Day 2
6/64
Shells
Shell accepts commands, interprets them and pass them tokernel.
bash
Most commonly used shell.
csh
Syntax is very familiar to the C- proramminglanguage
ksh
korn shell
tcsh
-
8/2/2019 Linux Unix Day 2
7/64
Linux Basics
Navigation and searching
-
8/2/2019 Linux Unix Day 2
8/64
Navigation
ls Lists the entries of a directory
lsa lists all, including system files.
mkdir cd PATH
cd takes the user to its home
pwd cp file 1 file2
-
8/2/2019 Linux Unix Day 2
9/64
Navigation
mv file1 file2
moves files or rename file
rm file removes a filermdir dir removes a directory
cat file prints the contents
whoami mank help or --help
-
8/2/2019 Linux Unix Day 2
10/64
File types
Text files
Store information in a readable text format
Binary data files
Store information associated with executable
programs
Executable program files
Directory files
-
8/2/2019 Linux Unix Day 2
11/64
File types
Linked filesAssociated with another file
Special device files
Represent system devicesNamed pipes
Identify channel that passes information
between processesSocket files
Allow a process on another computer to writeto a local file
-
8/2/2019 Linux Unix Day 2
12/64
Displaying content of a text file
Log files
File that contains past system event
cat commandtac command
Linux command that displays a file to the
screen beginning with the last line of the fileand ending with the first line of the file
-
8/2/2019 Linux Unix Day 2
13/64
Displaying content of a text file
headcommand
By default, displays the first 10 lines (including blank lines)
of a text file to the terminal screen
Can also take a numeric option specifying a differentnumber of lines to display
tail command
By default, displays the last 10 lines (including blank lines)
of a text file to the terminal screen
Can also take a numeric option specifying a different
number of lines to display
-
8/2/2019 Linux Unix Day 2
14/64
Displaying content of a text file
more command
less command
Displays a text file page-by-page on the terminal
Better thanmore
Exit with q
Themore and less commands can also be used in
conjunction with the output of other commandsIf output is too large to fit on terminal screen, use |
metacharacter, e.g. ls -l | more
-
8/2/2019 Linux Unix Day 2
15/64
Searching files
updatedb
locate file
findname file*findname * size +500k
grep string file
ls grep|newgrep b.*g file
-
8/2/2019 Linux Unix Day 2
16/64
Searching files
which commandCommand used to locate files that exist
within directories listed in the PATH
variablePATH variable
Lists directories on system where executable
files are located
Allows executable files to be run without
specifying absolute or relative path
-
8/2/2019 Linux Unix Day 2
17/64
Manipulation
vi file
opens a file in current directory for editing.
commands: :q :q!
:w
:wq
/ -searching string
Select some text to copy it, and right click pastes it.
-
8/2/2019 Linux Unix Day 2
18/64
Manipulation
emacsEmacs is more than "just an editor" -- it provides a fully integrateduser environment offering the sort of facilities outlined below. Issue shell comands
Read and send mail
Read news Access the internet
Write and test programs
Maintain a calendar
Play a game!
nano gedit
-
8/2/2019 Linux Unix Day 2
19/64
Linux Devices
/etc
-
8/2/2019 Linux Unix Day 2
20/64
The /dev Directory
Device file
File representing a device
Typically found in the /dev directory
Character devices Transfer data to and from the system one data bit
at a time
Block devices Transfer to and from the system in chunks ofmany bits by caching the information in RAM
Represented by block device files
Fast data transfer
-
8/2/2019 Linux Unix Day 2
21/64
The /dev Directory
BlockDefault CD-ROM/DVD-ROM drive/dev/cdrom
BlockFirst primary partition on the first SCSI hard disk drive/dev/sda1
BlockFirst primary partition on the fourth IDE hard disk drive(secondary slave)
/dev/hdd1
BlockFirst primary partition on the third IDE hard disk drive
(secondary master)
/dev/hdc1
BlockFirst primary partition on the first IDE hard disk drive
(primary master)
/dev/hda1
BlockFirst primary partition on the second IDE hard disk drive
(primary slave)
/dev/hdb1
Second floppy disk on the system
First floppy disk on the system
Description
Block/dev/fd1
Block/dev/fd0
Block or
CharacterDevice File
Common device files
-
8/2/2019 Linux Unix Day 2
22/64
The /dev Directory
Major number
Used by the kernel to identify what device
driver to call to interact properly with agiven category of hardware
Minor number
Used by the kernel to identify whichspecific hardware device, within a givencategory, to use a driver to communicatewith
-
8/2/2019 Linux Unix Day 2
23/64
The /dev Directory Device file type (block or character),
major number, and minor number makeup a device files unique characteristics
lrwxrwxrwx 1 root root 8 May 2 11:33 cdrom -> /dev/hdc
brw-rw---- 1 root disk 3, 0 Feb 23 2004 hda
brw-rw---- 1 root disk 3, 1 Feb 23 2004 hda1
mknodcommand
Can be used to re-create a corrupted
device file Must know file type, major, and minor
numbers
-
8/2/2019 Linux Unix Day 2
24/64
Filesystem Types
Third extended filesystem; a variation on ext2 that allows
for journaling and thus has a faster startup and recovery
time
ext3
Second extended filesystemcurrently the most common
filesystem used on Linux, it supports Access Control Lists
(individual user permissions). It retains its name from being
the new version of the original extended filesystem, based
on the Minix filesystem
ext2
Compact disc filesystemused to view all tracks and data
on a CD-ROM as normal files
cdfs
Boot File Systema small bootable filesystem used to hold
the files necessary for system startup; it is commonly used
on UNIX systems
bfs
DescriptionFilesystem
Common Linux filesystems
-
8/2/2019 Linux Unix Day 2
25/64
Filesystem Types
The DOS FAT filesystemmsdos
The DOS FAT filesystem with long file name supportvfat
The MINIX filesystemfilesystem used by Linus Torvalds
in the early days of Linux development
minix
Hierarchical File Systema filesystem native to Apple
Macintosh computers
hfs
The CD-ROM filesystemoriginated from the International
Standards Organization recommendation 9660 and used
to access data stored on CD-ROMs
iso9660
High Performance File Systeman IBM-proprietary OS/2
filesystem that provides long file name support and is
optimized to manipulate data on large disk volumes
hpfs
DescriptionFilesystem
Common Linux filesystems
-
8/2/2019 Linux Unix Day 2
26/64
Filesystem Types
New Technology File Systema Microsoft-proprietary
filesystem developed for its NT4 and Windows 2000
operating systems, currently available as a read-only
filesystem under Linux
ntfs
The Veritas filesystema journaling filesystem that offers
large file support, supports Access Control Lists (individual
user permissions), and is commonly used by major
versions of UNIX
vxfs
The Universal Disk Format filesystemA filesystem used
by software systems that write to a CD-R, CD-RW or DVD
udf
The REISERFS filesystema journaling filesystem similar
to ext3 more suited for use with databases
reiserfs
DescriptionFilesystem
Common Linux filesystems
-
8/2/2019 Linux Unix Day 2
27/64
Mounting Mounting
Making a device accessible to users via thelogical directory tree
Term originated in the 1960s, wheninformation was stored on large tape reelsthat had to be mounted on computers tomake the data available
Mount point
Directory in a file structure to which a deviceis attached
Any existing directory can be a mount point
-
8/2/2019 Linux Unix Day 2
28/64
Mounting/
mnt root
floppy cdrom
homedata etc
mary bob sue
The filesystem prior to mounting
-
8/2/2019 Linux Unix Day 2
29/64
Mounting/
mnt root homedata etc
mary bob sue
The directory structure after mounting a floppy device
/mnt
-
8/2/2019 Linux Unix Day 2
30/64
Mounting/
mnt root
cdrom
homedata etc
mary bob sue
The directory structure after mounting a floppy device
correctly
floppy
/mnt/floppy
-
8/2/2019 Linux Unix Day 2
31/64
Mounting
When the Linux filesystem is firstturned on, a filesystem present on the
hard drive is mounted to the / directory Root filesystem
Filesystem that contains files that start up
the operating system Should have enough free space to
prevent errors and slow performance
-
8/2/2019 Linux Unix Day 2
32/64
Mounting
mount command
Used to mount devices to mount point
directories With no options or arguments, lists
currently mounted filesystems
umount command Used to unmount devices from mount
point directories
-
8/2/2019 Linux Unix Day 2
33/64
Working with Floppy Disks
When transferring small amounts ofinformation from computer tocomputer, it is commonplace to usefloppy disk removable media to storethe files However, floppy disks must be prepared
before they are used in Linux Each disk device must be formatted with a
filesystem prior to being used to store files
-
8/2/2019 Linux Unix Day 2
34/64
Working with Floppy Disks
mkfs (make filesystem) command
Used to format a disk with a filesystem
t option: Specifies filesystem type Default is ext2 filesystem
To mount or unmount floppies, must
ensure that no user is currently usingthe mount point directory
-
8/2/2019 Linux Unix Day 2
35/64
Working with Floppy Disks
fuser command
With the u option, lists users using a
directory Most (almost all) floppy disks today
come preformatted with the DOS FATfilesystem
Will work just fine for Linux when mountedcorrectly
(Work on Macs as well)
-
8/2/2019 Linux Unix Day 2
36/64
Working with Floppy Disks
Used to create a REISERFS filesystemmkfs.reiserfs
mkreiserfs
Used to create a CD-ROM filesystemmkisofs
Used to create an ext3 filesystem (j = journaling)mkfs.ext3
mke2fs -j
Used to create an ext2 filesystemmkfs.ext2mke2fs
Used to create a DOS FAT filesystemmkfs.msdos
mkdosfs
mkfs.vfat
Used to create filesystems of most typesmkfs
DescriptionCommand
Commands used to create filesystems
-
8/2/2019 Linux Unix Day 2
37/64
Working with Floppy Disks
/etc/fstab file
Used to mount devices at boot time
Also consulted when users do not specifyenough mount command arguments
Six fields: Device to mount, mount point,
type, mount options, dump#, fsck#
-
8/2/2019 Linux Unix Day 2
38/64
Working with Floppy Disks
Unmounts a from
its directory
umount
or
umount
Displays the users using aparticular directory
fuser -u
Mounts a of a
certain to a directory
mount -t
Displays mounted
filesystems
mount
DescriptionCommand
Useful commands when mounting and unmountingfilesystems
-
8/2/2019 Linux Unix Day 2
39/64
Working with Floppy Disks
Mounting a
floppy deviceusing a GUI
environment
-
8/2/2019 Linux Unix Day 2
40/64
Working with Floppy Disks
Unmounting a
floppy devicein
a GUI
environment
-
8/2/2019 Linux Unix Day 2
41/64
Working with CD-ROMs
CD-ROMs are normally mounted as/dev/cdromdespite occupying one of
the hard drive block device designations Typically use iso9660 filesystem type
and are not writable
Mount with
r(read-only) option
Cannot be ejected until properlyunmounted
-
8/2/2019 Linux Unix Day 2
42/64
Working with CD-ROMs
Viewing the
contents of aCD-ROM
device in
a GUI
environment
-
8/2/2019 Linux Unix Day 2
43/64
Working with CD-ROMs
Unmounting a
CD-ROMdevice in
a GUI
environment
-
8/2/2019 Linux Unix Day 2
44/64
Working with Hard Disks
IDE hard disk drives attach to themainboard with an IDE cable and mustbe configured on one of four
configurations, each of which has adifferent device file:
Primary master (/dev/hda)
Primary slave (/dev/hdb)
Secondary master (/dev/hdc)
Secondary slave (/dev/hdd)
-
8/2/2019 Linux Unix Day 2
45/64
Working with Hard Disks
SCSI hard disks well-suited to Linuxservers
Faster access speed
Multiple hard drives can be attached to acontroller
Associated with different device files
First SCSI HDD (/dev/sda)
Second SCSI HDD (/dev/sdb)
Third SCSI HDD (/dev/sdc) and so on.
-
8/2/2019 Linux Unix Day 2
46/64
Hard Disk Partitioning
As disk size increases, organizationbecomes more difficult and chance oferror increases
Partition
A physical division of a hard disk drive
Can have its own filesystem
-
8/2/2019 Linux Unix Day 2
47/64
Hard Disk Partitioning
It is good practice to use more than justtwo partitions
Segregates different types of data Allows for use of multiple filesystem types on one
HDD
Reduces the chance the filesystem corruption
will render a system unusable Speeds up access to stored data by keeping
filesystems as small as possible
-
8/2/2019 Linux Unix Day 2
48/64
Hard Disk Partitioning
Tracks
Area on a hard disk that form a concentriccircle of sectors
Sector
Smallest unit of data storage on a harddisk
Block
Unit of data commonly used by filesystemcommands
-
8/2/2019 Linux Unix Day 2
49/64
Hard Disk Partitioning
Cylinder
Series of tracks on a hard disk that are
written to simultaneously by the magneticheads in a hard disk drive
Partition definitions stored in first readablesector of the hard disk
Master Boot Record (MBR) or master boot block(MBB)
-
8/2/2019 Linux Unix Day 2
50/64
Hard Disk Partitioning
Track
Sector
Block
The physical
areas of a harddrive
-
8/2/2019 Linux Unix Day 2
51/64
Hard Disk Partitioning
Common hard disk partition device files for
/dev/hda and /dev/sda
SCSI Device Name
(assuming /dev/sda1)
IDE Device Name
(assuming /dev/hda1)
Partition
/dev/sdan/dev/hdannth logical drive in the extended partition
/dev/sda9/dev/hda95th logical drive in the extended partition
/dev/sda8/dev/hda84th logical drive in the extended partition
/dev/sda7/dev/hda73rd logical drive in the extended partition
/dev/sda6/dev/hda62nd logical drive in the extended partition
/dev/sda5/dev/hda51st logical drive in the extended partition
/dev/sda4/dev/hda44th primary partition
/dev/sda3/dev/hda33rd primary partition
/dev/sda2/dev/hda22nd primary partition
/dev/sda1/dev/hda11st primary partition
-
8/2/2019 Linux Unix Day 2
52/64
Hard Disk Partitioninghda1primary
hda5logical
MBR(MBB)
Freespace
swap1GB
hda5 + free space = hda2extended
A sample Linux partitioning strategy
/ (Linux)
9GB
-
8/2/2019 Linux Unix Day 2
53/64
Hard Disk Partitioninghda1primary
hda7logical
MBR(MBB)
Freespace
Swap1GB
hda5 + hd6 + hd7 + free space= hda2(extended)
A sample dual-boot Linux partitioning strategy
hda5logical
hda6logical
C:\win984GB
/home5GB
/ (Linux)
9GB
-
8/2/2019 Linux Unix Day 2
54/64
Working with Hard Disk
Partitions Disk Druid is an easy-to-use partitioningtool used with Red Hat Linux, specifically
designed for installation only fdisk command
Used to create partitions after installation
Specify hard disk partition as an argument
-
8/2/2019 Linux Unix Day 2
55/64
Working with Hard Disk Partitions
tune2fs command
Create a journal file on the filesystem
Convert ext2 to ext3
Edit /etc/fstab file to allow system
to mount new filesystems automatically
at boot time
-
8/2/2019 Linux Unix Day 2
56/64
Monitoring Filesystems
Check mounted filesystemsperiodically
Errors
Disk Space usage
Inode usage
-
8/2/2019 Linux Unix Day 2
57/64
Disk Usage
Using more filesystems typically resultsin less hard disk space per filesystem
Errors when filesystems fill up with data
e.g., free space on / filesystem falls below 10%
df (disk free space) command
Monitor free space used by mounted
filesystems
h option: More user friendly
-
8/2/2019 Linux Unix Day 2
58/64
Disk Usage
du (directory usage) command
View size of a directory and contents in
Kilobytes s option: Summarizes output
dumpe2fs command
View total number of inodes and freeinodes for ext2 or ext3 filesystem
Use h option
-
8/2/2019 Linux Unix Day 2
59/64
Checking Filesystems for
Errors Filesystem corruption Errors in a filesystem structure that prevent the
retrieval of stored data
Commonly occurs due to improper system shutdown Syncing
Process of writing data stored in RAM to the HDD
Bad blocks Unusable areas of a disk
Cannot hold a magnetic charge
-
8/2/2019 Linux Unix Day 2
60/64
Checking Filesystems for
Errors fsck (filesystem check) command
Check a filesystem for errors
Filesystem must be unmounted
f option used to perform full check
e2fsck command
Check ext2 and ext3 filesystems
reiserfsck
Check reiserfs filesystems
-
8/2/2019 Linux Unix Day 2
61/64
Checking Filesystems for
Errors
Common options to the fsck command
Displays verbose output-V
Checks all filesystems in /etc/fstab that have a 1 or 2 in
the sixth but skips field the / filesystem
-AR
Performs a full filesystem check and displays a progressline
-Cf
Checks all filesystems in /etc/fstab that have a 1 or 2 in thesixth field
-A
Allows fsck to repair any errors automatically-a
Performs a full filesystem check-f
DescriptionOption
-
8/2/2019 Linux Unix Day 2
62/64
Hard Disk Quotas
If several users on a system, must be enoughhard disk space for each users files
Hard disk quotas
User limits on filesystem usage Restrict number of files/directories or total disk
space usage
Soft limits
Limit imposed that can be exceeded for a certainperiod of time
Hard limit
Limit imposed that cannot be exceeded
-
8/2/2019 Linux Unix Day 2
63/64
Hard Disk Quotas (continued)
quotaon and quotaoff commands
Toggle quotas on and off
edquota command
Edit user quotas
repquota command
Report user quotas
quota command
Allows regular users to view quotas andcurrent usage
-
8/2/2019 Linux Unix Day 2
64/64
Checking Filesystems for
Errors
Common options to the fsck command
Displays verbose output-V
Checks all filesystems in /etc/fstab that have a 1 or 2 in
the sixth but skips field the / filesystem
-AR
Performs a full filesystem check and displays a progressline
-Cf
Checks all filesystems in /etc/fstab that have a 1 or 2 in thesixth field
-A
Allows fsck to repair any errors automatically-a
Performs a full filesystem check-f
DescriptionOption