• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/596

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

596 Cards in this Set

  • Front
  • Back
filenames can begin with a dot and ....
These socalled dot files are hidden from view by most utilities that display files, so they’re popular for storing configuration files in your home directory.
single dot (.) refers to

filename that consists of a double dot (..) refers to
(.) current dir

(..) refers to the parent directory
Characters enclosed in square brackets ([]) normally match
any character in the set.
For instance, b[ao][lo]k matches balk and book but not buck
For instance, b[a–z]ck matches back, buck, and other four–letter filenames of this form whose second character is a lowercase letter
ls Command
ls [options] [files]

ls command displays the names of files in a directory
ls options
–a
––color
–d
–l
–a or ––all parameter displays dot files
––color option produces a color–coded listing that differentiates directories, symbolic links, and so on by displaying them in different colors
–d or ––directory parameter changes this behavior to list only the directory name, which is sometimes preferable
–l produces a long listing that includes information such as the file’s permission strin
ls options
–F
–F or ––file–type option appends an indicator code to the end of each name so you know what type of file it is. the meanings are as follows:
/ Directory
@ Symbolic link
= Socket
| Pipe
ls options
–R
–R or ––recursive option causes ls to display directory contents recursively. That is, if the target directory contains a subdirectory, ls displays both the files in the target directory and the files in its subdirectory
cp Command
copies a file

cp [options] source destination
cp options
–f
–i
–p
–f or ––force option forces the system to overwrite any existing files without prompting

–i or ––interactive option causes cp to ask you before overwriting any existing files.

–p or ––preserve option preserves ownership and permissions, if possible.
cp options
–R
–a
–u
–R or ––recursive option and specify a directory as the source, the entire directory, including its subdirectories, is copied.

–a or ––archive option is similar to –R, but it also preserves ownership and copies links as is

–u or ––update option tells cp to copy the file only if the original is newer than the target or if the target doesn’t exist
ollowing command copies the /etc/fstab configuration file to a backup location in /root, but only if the original /etc/fstab is newer than the existing backup
# cp –u /etc/fstab /root/fstab–backup
mv Command
mv command (short for move) is commonly used both to move files and directories from one location to another and to rename them

mv [options] source destination
mv options
–f
–i
–f or ––force option forces the system to overwrite any existing files without prompting

–i or ––interactive option causes cp to ask you before overwriting any existing files.
command copies the document.odt file into the important/purchases subdirectory
$ mv document.odt important/purchases/
touch Command
Linux–native filesystems maintain three time stamps for every file:
– Creation time
– Last modification time
– Last access time

touch [options] files

1)By default, touch sets the modification and access times to the current time
2)the specified files don’t already exist, touch creates them as empty files
touch options
–a
–m
–c
–t
–a or ––time=atime option causes touch to change the access time alone
–m or ––time=mtime option causes touch to change the modification time alone
–c or ––no–create option If you don’t want touch to create any files that don’t already exist
–t timestamp option sets the time to the specified timestam
tar Utility
tar program’s name stands for “tape archiver”
tar cmds
––create

––concatenate

––append

––update
abr
––create – c – Creates an archive
––concatenate – A – Appends tar files to an archive
––append – r – Appends non–tar files to an archive
––update – u – Appends files that are newer than those in an archive
tar cmds
––diff or ––compare

––list

––extract or ––get
abr
––diff or ––compare – d – Compares an archive to files on disk
––list – t – Lists an archive’s contents
––extract or ––get – x – Extracts files from an archive
tar qualifiers
––directory dir

––file [host:]file

––listed–incremetnal file
abr
––directory dir – C – Changes to directory dir before performing operations
––file [host:]file – f – Uses the file called file on the computer called host as the archive file
––listed–incremental file – g – Performs an incremental backup or restore, using file as a list of previously archived files
tar qualifiers
––one–file–system
––multi–volume
––tape–lenth N
––same–permissions
––one–file–system – l – Backs up or restores only one filesystem (partition)
––multi–volume – M – Creates or extracts a multi–tape archive
––tape–length N – L – Changes tapes after N kilobytes
––same–permissions – p – Preserves all protection information
tar qualifiers
––absolute–paths
––verbose
––verify
––exclude file
––absolute–paths – P – Retains the leading / on filenames
––verbose – v – Lists all files read or extracted; when used
with ––list, displays file sizes, ownership, and time stamps
––verify – W – Verifies the archive after writing it
––exclude file – (none) – Excludes file from the archive
tar qualifiers
––exclude–from file
––gzip or ––ungzip
––bzip2
––exclude–from file – X – Excludes files listed in file from the archive
––gzip or ––ungzip – z – Processes an archive through gzip
––bzip2 – j – Processes an archive through bzip2
archiving and compressing the my–work subdirectory of your home directory to a USB pen drive mounted at /media/pen
$ tar cvfz /media/pen/my–work.tgz ~/my–work
pen drive to another system, mount it at /media/usb, and want
to extract the archive, you can do so with another command
$ tar xvfz /media/usb/my–work.tgz
cpio Utility
cpio program is similar in principle to tar, but the details of its operation differ.
The cpio utility has three operating modes:
Copy–out mode
This mode, activated by use of the –o or ––create option, creates an archive and copies files into it.
Copy–in mode
You activate copy–in mode by using the –i or ––extract option. This mode extracts data from an existing archive. If you provide a filename or a pattern to match, cpio extracts only the files whose names match the pattern you provide.
Copy–pass mode
This mode is activated by the –p or ––pass–through option. It combines the copy–out and copy–in modes, enabling you to copy a directory tree from one location to another.
Options for Use with cpio
––reset–access–time
––append
––pattern–file=filename
––file=filename
––reset–access–time – abbr – –a Resets the access time after reading a file so that it doesn’t appear to have been read.
––append – abbr –A – Appends data to an existing archive.
––pattern–file=filename – abbr. –E filename – Uses the contents of filename as a list of files to be extracted in copy–in mode.
––file=filename – abbr –F filename – Uses filename as the cpio archive file; if this parameter is omitted, cpio uses standard input or output.
Options for Use with cpio
––format=format
–I filename
––no–absolute–filenames
–O filename
––format=format –H format Uses a specified format for the archive file. Common values for format include bin (the default, an old binary format), crc (a newer binary format with a checksum), and tar (the format used by tar).
–I filename Uses the specified filename instead of standard input.
––no–absolute–filename – In copy–in mode, extracts files relative to the current directory, even if filenames in the archive contain full directory paths.
–O filename Uses the specified filename instead of standard output
Options for Use with cpio
––list
––unconditional
––verbose
––list – abbr –t – Displays a table of contents for the input.

––unconditional – abbr –u – Replaces all files without first asking for
verification.

––verbose – abbr –v – Displays filenames as they’re added to or
extracted from the archive. When used with –t, displays additional listing information (similar to ls –l).
use cpio to archive a directory, you must pass a list of files to the utility using standard input
$ find ./my–work | cpio –o > /media/pen/my–work.cpio
use cpio to archive a directory, you must pass a list of files to the utility using standard input with compression
$ find ./my–work | cpio –o | gzip > /media/pen/my–work.cpio.gz
Extracting data from an uncompressed cpio archive (say, on another computer with the media mounted at /media/usb) entails using the –i option, but no pipe is required:
$ cpio –i < /media/usb/my–work.cpio
If your cpio archive is compressed, you must first uncompress it with gunzip. By using the –c option to this command, you can pass its output to cpio in a pipe:
$ gunzip –c /media/usb/my–work.cpio.gz | cpio –i
dd Utility
archive a filesystem at a very low level. This utility is a low–level copying program, and when it’s given the device file for a partition as input, it copies that partition’s contents to the output file you specify.

# dd if=/dev/sda3 of=/dev/st0
backs up the /dev/sda3 disk partition to /dev/st0 (a SCSI tape drive).
# dd if=/dev/sda3 of=/dev/st0
dd restore from /dev/sda3
# dd if=/dev/st0 of=/dev/sda3
dd utility shortcoming
good way to create exact backups of entire partitions but
backs up the entire partition, including any empty space
Restoring individual files is also impossible unless the target device is a random access device that can be mounted
you can’t easily restore data to a partition that’s smaller than the original partition

good for CD–ROM
/dev/zero device
a Linux device that returns nothing but zeroes
if you need an empty file of a
particular size
$ dd if=/dev/zero of=empty–file.img bs=1024 count=720

creates a 720KB (1024 × 720 bytes) empty file
In Linux, a link is a ?
In Linux, a link is a way to give a file multiple identities, similar to shortcuts in Windows and aliases in Mac OS.
Two types of links exist:
hard links and soft links (a.k.a.
symbolic links).
ln command
ln command creates links.

ln [options] source link

source is the original file, and the link is the name of the link you want to create
ln cmd options
–f
–i
–d, –F
–s
–f or ––force option
causes ln to remove any existing links or files that have the target link name
–i or ––interactive option
causes ln to remove any existing links or files that have the target link name but queireis
–d, –F, or ––directory
Ordinarily, you can’t create hard links to directories. The root user can attempt to do so, though, by passing the –d, –F, or ––directory option to ln
–s or ––symbolic option
ln command creates hard links by default. To create a symbolic
link, use –s
mkdir Command
mkdir command creates a directory

mkdir [options] directory–name(s)
mkdir options
–m
–p
–m mode or ––mode=mode option causes the new directory to have the specified permission mode, expressed as an octal number
–p or ––parents option
if you specify the creation of a directory within a directory that doesn’t exist, mkdir responds with a No such file or directory error with –p option creates the parent
rmdir Command
destroys a directory

rmdir [options] directory–name(s)
delete one/two/three, then
one/two, and finally one
rmdir –p one/two/three

–p or ––parents option causes rmdir to delete an entire directory tree
learn who owns a file
ls command

$ ls –l
total 1141
–rw–r––r–– 1 rodsmith users 219648 Mar 8 13:06 4425ch02.doc
–rw–r––r–– 1 rodsmith users 942590 Mar 6 23:31 f0201.tif

rodsmith – username of the owner
users – group name
Changing a File’s Owner
change a file’s ownership using the chown command

chown [options] [newowner][:newgroup] filenames
chown option
–R
–R or ––recursive, which implements the ownership change on an entire directory tree.
Changing a File’s Group
changes a file’s group

chgrp [options] newgroup filenames
file type code
ls –l test
–rwxr–xr–x 1 rodsmith users 111 Apr 13 13:48 test

The first character has special meaning—it’s the file type code. The type code determines how Linux will interpret the file—as ordinary data, a directory, or a special file type
Linux File Type Codes

d
l
p
– Normal data file;

d Directory;

l Symbolic link; the file contains the name of another file or directory. When Linux accesses the symbolic link, it tries to read the linked–to file.

p Named pipe; a pipe enables two running Linux programs to communicate with each other.
Linux File Type Codes
s
b
c
s Socket; a socket is similar to a named pipe, but it permits network and bidirectional links.

b Block device; a file that corresponds to a hardware device to and from which data is transferred in blocks of more than one byte. Disk devices (hard disks, floppies, CD–ROMs, and so on) are common block devices

c Character device; a file that corresponds to a hardware device to and from which data is transferred in units of one byte. Examples include parallel and RS–232 serial port devices.
Meanings of Permission Bits
2 to 10
$ ls –l test
–rwxr–xr–x 1 rodsmith users 111 Apr 13 13:48 test
first char – file type code
2 to 10 are broken in 3 groups of 3 chars:
first group controls the file owner's access to files
second group controls the group's access to the file
third controls all other users' access to the file
Meanings of Permission Bits (2 to 10) each group (permission string)
the permission string determines the presence or absence of each of three types of access: read, write, and execute.
The absence of the permission is denoted by a dash (–) in the permission string.
permission bits (def)
Individual permissions, such as execute access for the file’s owner, are often referred to as permission bits
one digit for each of the owner, group, and world permissions
1 for execute permission,
2 for write permission, and
4 for read permission
permission string vs octal code
rwxrwxrwx

rwxr–xr–x

rwxr–x–––
rwxrwxrwx – 777 – Read, write, and execute permissions for all users.
rwxr–xr–x – 755 – Read and execute permission for all users. The file’s owner also has write permission.
rwxr–x––– – 750 – Read and execute permission for the owner and group. The file’s owner also has write permission. Users who
aren’t the file’s owner or members of the group have no access to the file.
permission string vs octal code
rwx––––––
rw–rw–rw–
rw–rw–r––
rwx–––––– – 700 – Read, write, and execute permissions for the file’s owner only; all others have no access.
rw–rw–rw– – 666 – Read and write permissions for all users. No execute permissions for anybody.
rw–rw–r–– – 664 – Read and write permissions for the owner and group. Read–only permission for all others.
permission string vs octal code
rw–rw––––
rw–r––r––
rw–r–––––
rw–rw–––– – 660 – Read and write permissions for the owner and group. No world permissions.
rw–r––r–– – 644 – Read and write permissions for the owner. Read–only permission for all others.
rw–r––––– – 640 – Read and write permissions for the owner, and readonly permission for the group. No permission for others.
permission string vs octal code
rw–––––––
r––––––––
rw––––––– – 600 – Read and write permissions for the owner. No permission for anybody else.
r–––––––– – 400 – Read permission for the owner. No permission for anybody else.
Symbolic links are unusual with respect to permissions
This file type always has 777 (rwxrwxrwx) permissions, thus granting all users full access to the file. This access applies
only to the link file itself, however, not to the linked–to file
SUID
Set user ID (SUID)
used in conjunction with executable files, and it tells Linux to run the program with the permissions of whoever owns the file rather than with the permissions of the user who runs the program
SUID programs are indicated by an s in the owner’s execute bit position in the permission string, as in
rwsr–xr–x.
SGID
set group ID (SGID)
sets the group of the running program to the group of the file. It’s indicated by an s in the group execute bit position in the permission string, as in rwxr–sr–x. When the SGID bit is set on a directory, new files or subdirectories created in the original directory will inherit the group ownership of the directory, rather than be based on the user’s current default group
Sticky bit
In modern Linux implementations
it’s used to protect files from being deleted by those who don’t own the files. When this bit is present on a directory, the directory’s files can be deleted only by their owners, the directory’s owner, or root. The sticky bit is indicated by a t in the world execute bit position, as in rwxr–xr–t.
Linux ACLs
new and improved permission system
consist of three permission bits, one each for read, write, and execute permissions
file’s owner can assign ACLs to an arbitrary number of users and groups, making ACLs more flexible than Linux permissions, which are limited to groups defined by the system administrator

ACLs require their own commands to set and view. The setfacl command sets an ACL, and the getfacl command displays the ACLs for a file.
command sets an ACL
command displays the ACLs for a file
setfacl
getfacl
suppose you’ve acquired a script called bigprogram. You want to set both SUID and SGID bits (6); to make the program readable, writeable, and executable by the owner (7); to make it readable and executable by the group (5); and to make it completely inaccessible to all others (0).
$ ls –l bigprogram
–rw–r––r–– 1 rodsmith users 10323 Oct 31 18:58 bigprogram
$ chmod 6750 bigprogram
$ ls –l bigprogram
–rwsr–s––– 1 rodsmith users 10323 Oct 31 18:58 bigprogram
symbolic mode permission set code
u – Owner
g – Group
o – World
a – All
symbolic mode change type code
+ – Add
– – Remove
= – set equal to
symbolic mode permissions to modify code
r – Read
w – Write
x – Execute
X – Execute only if the file is a dir or already has execute permission
s – SUID or SGID
t – Sticky bit
u – existing owner's permissions
g – existing group permission
0 – existing world permissions
rw–r––r––
chmod a+x bigprogram will cause
rw–r––r––
chmod a+x bigprogram will cause
rwxr–xr–x
r––––––––
chmod ug=rw report.tex
r––––––––
chmod ug=rw report.tex
rw–rw––––
rwxrwxr–x
chmod o–rwx bigprogram
rwxrwxr–x
chmod o–rwx bigprogram
rwxrwx–––
rw–r––r––
chmod g=u report.tex
rw–r––r––
chmod g=u report.tex
rw–rw–r––
rw–rw–rw–
chmod g–w,o–rw report.tex
rw–rw–rw–
chmod g–w,o–rw report.tex
rw–r–––––
umask command
When a user creates a file, that file has default ownership and permissions.
The default group is the user’s primary group.
The default permissions are configurable. These are defined by the user mask (umask), which is set by the umask command
Special Permission Bits list
SUID – Set user ID
SGID – Set group ID
Sticky bit
When a user creates a file what ownership and permissions are
When a user creates a file, that file has default ownership and permissions. The default owner is, user who created the file.
The default group is the user's primary group.
Permissions are configurable with user mask which is manipulated by umask command
Sample Umask Values and Their Effects
000
002
022
Umask – Created Files – Created Dir
000 – 666 (rw–rw–rw–)– 777 (rwxrwxrwx)
002 – 664 (rw–rw–r––) – 775 (rwxrwxr–x)
022 – 644 (rw–r––r––) – 755 (rwxr–xr–x)
Sample Umask Values and Their Effects
027
077
277
Umask – Created Files – Created Dir
027 – 640 (rw–r–––––) – 750 (rwxr–x–––)
077 – 600 (rw–––––––) – 700 (rwx––––––)
277 – 400 (r––––––––) – 500 (r–x––––––)
How superuser can set default setting fro all users
Edit
/etc/profile
contains unmask commands
find what the current umask is use
umask –S
umask u=rwx,g=rx,o=rx is equivalent to
umask 022
users can change their default group
with
newgrp

newgrp skyhook
create new files with the group set to the skyhook group
newgrp –l cmd
newgrp –l skyhook, which reinitializes the
environment as if the user had just logged in.
chattr command
allows you to change file attributes
chattr command options
a
c
i
j
a – append only
sets append mode, which disables writes access but allows append
c – compressed
causes the kernel to automatically compress data written to the file and uncompress it when it's read back
i – immutable
makes file immutable, can't be deleted, links to it can't be created, and file can't be renameed
j – data journaling
tells the kernel to journal all data wrtten to the file
chattr command options
s
t
A
s – secure deletion
when you delete a file it might still be available for recycling with s kernel zeros its data blocks
t – no tail–merging
A – no access time updates
Linux won't update the access time stamp when you access a file
Tail–merging def
is a process in which small pieces of data at the ends of files that don’t fill a complete block are merged with similar pieces of data from other files. The result is reduced disk space consumption
cmd to add the immutable flag to the important.txt
# chattr +i important.txt

to remove the immutable

# chattr –i important.txt
Two general quota support systems are available for Linux
quota v1 support – up to 2.4.x kernel
quota v2 system – added after 2.6.x
How is the package called that is used for the quota v2 system
called quota

it installs a number of utilities, configuration files, SysV startup scripts
what you must modify for any partitions on which you want to use quota support
You must modify your /etc/fstab entries for any partitions on which you want to use
quota support.

/dev/hdc5 /home ext3 usrquota,grpquota 1 1

This line activates both user and group quota support for the /dev/hdc5 partition which is mounter at /home
How can you set the quotas
edquota

which starts the Vi editor on a temporary configuration file (/etc/quotatab) that controls quotas for the user you specify.
When you exit the utility, edquota uses the temporary configuration file to write the quota information to low–level disk data structures that control the kernel’s quota mechanisms.
edquota –t
set the grace period by using edquota with its –t option
Grace periods are set on a per–filesystem basis rather than a per–user basis
quotacheck
which verifies and updates quota information on quota–enabled disks
repquota
repquota, which summarizes the quota information about the filesystem you specify or on all filesystems if you pass it the –a option.
quota –g
quota –l
quota –q
quota –g
displays group quotas

quota –l
omits NFS mounts

quota –q
limits output to filesystems on which usage is over the limit
FSSTND (abbr and def)
FSSTND – Filesystem Standard

FSSTND standardized several specific features
1)Standardized t NN he programs that reside in /bin and /usr/bin. Differences on this score
caused problems when scripts referred to files in one location or the other
2)Specified that executable files NN shouldn’t reside in /etc, as had previously been common.
3)Removed changeable files from the /usr directory tree, enabling it to be mounted readonly (a useful security measure)
FHS
FHS – Filesystem Hierarchy Standard
is based on FSSTND but extends it substantially
FHS shareable file
Shareable files may be reasonably shared between computers, such as user data files and program binary files. If files are shared, they’re normally shared through an NFS server
FHS unshareable file
contain system–specific information, such as configuration files. For instance, you’re not likely to want to share a server’s configuration file between computers
FHS static files
don’t normally change except through direct intervention by the
system administrator
FHS variable files
Variable files may be changed by users, automated scripts, servers, or the like
FHS /
every Linux filesystem traces its roots to the root filesystem/dir
Where /etc and /sbin should be location
must reside on the root partition
FHS /boot
/boot directory contains static and unshareable files related to the initial booting
of the computer.
FHS /etc
Higher–level startup and configuration files reside in /etc
FHS /bin
This directory contains certain critical executable files, such as ls, cp, and mount. These commands are accessible to all users and constitute the most important commands
that ordinary users might issue
FHS /sbin
directory is similar to /bin, but it contains programs that are normally run only by the system administrator—tools like fdisk and e2fsck
FHS /lib
similar to /bin and /sbin
it contains program libraries, which are made up of code that’s shared across many programs and stored in separate files to save disk space and RAM
/lib/modules
/lib/modules subdirectory contains kernel modules—drivers that can be loaded and unloaded as required.
FHS /usr
hosts the bulk of a Linux computer’s programs
FHS /usr/local
contains subdirectories that mirror the organization of /usr, such as /usr/local/bin and /usr/local/lib.
/usr/local directory hosts files that a system administrator installs locally
FHS /usr/X11R6
houses files related to the X Window System
FHS /opt
similar to /usr/local in many ways, but it’s intended for readymade packages that don’t ship with the OS, like commercial word processors or games. Typically, these programs reside in subdirectories in /opt named after themselves, such as /opt/applix.
FHS /home
This directory contains users’ data, and it’s shareable and variable. Although the /home
directory is considered optional in FHS, in practice it’s a matter of the name being optional.
FHS /root
home directory for the root user. Because the root account is so critical and system specific, this variable directory isn’t really shareable.
FHS /var
contains transient files of various types––system log files, print spool files, mail and news files, and so on
FHS /tmp
Many programs need to create temporary (hence variable) files, and the usual place
to do so is in /tmp.
FHS /mnt
Linux mounts removable–media devices within its normal directory structure, and
/mnt is provided for this purpose

/mnt, such as /mnt/floppy and /mnt/cdrom, to function as mount points
FHS /media
This directory is an optional part of the FHS. It’s like /mnt, but it should contain
subdirectories for specific media types, such as /media/floppy and /media/cdrom. Many modern distributions use /media subdirectories as the default mount points for common removable disk types.
FHS /dev
Linux treats most hardware devices as if they were files, the OS must have a location in its filesystem where these device files reside. The /dev directory is that place. It contains a large number of files that function as hardware interfaces.
FHS /proc
This is an unusual directory because it doesn’t correspond to a regular directory or partition. Instead, it’s a virtual filesystem that’s created dynamically by Linux to provide access to certain types of hardware information that aren’t accessible via /dev
displaying information about your
CPU—its model name, speed, and so on
cat /proc/cpuinfo
find Command
find utility implements a brute–force approach to finding files

find [path...] [expression...]
find
–name pattern

–perm mode

–gid GID
–name pattern
You can search for a filename using the –name pattern expression doing so finds files that match the specified pattern

–perm mode
If you need to find files that have certain permissions, you can do so by using the –term mode expression

–gid GID
searches for files whose group ID (GID) is set to GID
find
–size n

–group name

–uid UID
–size n
You can search for a file of a given size

–group name
option locates files whose group name is name

–uid UID
searches for files owned by the user whose
user ID (UID) is UID
find
–user name

–maxdepth levels
–user name
searches for files owned by name

–maxdepth levels
If you want to search a directory and, perhaps, some limited number of subdirectories, you can use the –maxdepth levels expression to limit the search
consider the task of finding all C source code files, which normally have names that end in .c, in all users’ home directories. If these home directories reside in /home, you might issue the following command:
# find /home –name “*.c”
locate cmd
locate utility works much like find if you want to find a file by name, but it differs in two important ways

1)far less sophisticated in its search options. You normally use it to search only on filenames, and the program returns all files that contain the specified string. For instance, when searching for rpm, locate will return other programs, like gnorpm and rpm2cpio.
2)locate program works from a DB that it maintains Most distributions include a cron job that calls locate with options that cause it to update its database periodically, such as once a night or once a week
slocate cmd
Some Linux distributions use slocate rather than locate

slocate program includes security features to prevent users from seeing the names of files in directories they shouldn’t be able to access
whereis cmd
searches for files in a restricted set of locations, such as standard binary file directories, library directories, and man page directories
This tool does not search user directories or many other locations that are easily searched by find or locate.
cmd locates ls
$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.bz2

result shows both the ls executable (/bin/ls) and the ls man page
which cmd
Considered as a search command, which is very weak; it merely searches your path for the command that you type and lists the complete path to the first match it find.
For instance, you might want to know
where the xterm program is located:

$ which xterm
/usr/bin/xterm
type Command
ommand isn’t really a search command; instead, it tells you how a command you
type will be interpreted—as a built–in command, an external command, an alias, and so on.

$ type type
type is a shell builtin
$ type cat
cat is /bin/cat
$ type ls
ls is aliased to `ls ––color’
boot loader
boot loader is the software that the BIOS reads and executes when the system begins to boot.
master boot record (MBR) contains the partition table and a boot loader (also sometimes called a boot manager)
two boot loaders are important in Linux
Linux Loader (LILO)
Grand Unified Boot Loader (GRUB)
GRUB
LILO
Linux Loader (LILO)
Grand Unified Boot Loader (GRUB)
third–party boot loaders
System Commander
BootMagic.
superblock
describes basic filesystem features, such as the filesystem’s size and status

debugfs and dumpe2fs commands, provide some basic superblock information
Configuring LILO
You configure LILO using the /etc/lilo.conf file

broken into two main sections: global and per–image options
/etc/lilo.conf options
boot=

default=
boot=
specifies the name of the device that contains the boot sector

default=
specifies the default kernel or OS that boots. If this
option is omitted, the first image listed in lilo.conf is used as the default
/etc/lilo.conf options
prompt

timeout=
prompt
instructs LILO to issue the boot: prompt and wait for
user input. This option is usually desirable, but it can be omitted if you want the system to
directly boot a single configuration

timeout=
setting specifies the amount of time, in tenths of a second, that LILO will wait for keyboard input before booting the default kernel image. You must use
the prompt option to enable the timeout
/etc/lilo.conf options
lba32

vga=
lba32 option
enables LILO to boot from disks where the kernel
image resides on a partition that is past the 1,024th cylinder. This option is almost always desirable, but you may omit it if you’re using a very old computer.

vga=
selects the VGA text mode that is used when booting. Choices include normal, extended, ask, and a number
/etc/lilo.conf options
root=

read–only
root= option
passed to the Linux kernel to tell it what partition to use as its root (/) partition. You can set a default value for this option and override it in individual stanzas,

read–only option
indicates that the root filesystem should be mounted read–only. Usually, the operating system will remount the filesystem to read–write
Want to password–protect your booting process
password,
restricted,
mandatory, and
bypass
options, which are documented in the man page for lilo.conf.
stanzas support by LILO
LILO supports two main types of stanzas: those for Linux kernels and those for other OSs.
LILO per–image options

image=

other=
image=
indicates the Linux kernel file to use when booting.
You must pass the complete path to the Linux kernel image file.

other=
indicates the partition that contains its own boot loader. When this option is selected, LILO passes control to the boot loader in that partition. DOS, Windows, OS/2, BeOS, FreeBSD, and other OSs can all place their own
boot loaders in their partitions, so this tool enables you to pass control to these OSs.
LILO per–image options
label=

initrd=

append=
label=
rovides a name for LILO to use. When you boot, you type the name of the label or press the Tab key to get a list of available labels

initrd=
points to an initial RAM disk. This is a small filesystem in a file that the boot loader loads into memory and delivers to the kernel as a RAM–based substitute for a disk drive. Linux distributions frequently use RAM disks like this to store kernel drivers as a way of keeping the kernel size down while still supporting a wide range
of drivers

append=
You can pass arbitrary options to the kernel with the append= option
lilo cmd
This command installs LILO in the MBR or boot partition’s boot sector. You should see a list of stanza names echo to the screen. Ensure that your new configuration is present
lilo cmd options
–t
–c
–v
–b
–C config–file option specifies an alternate
configuration file to use rather than /etc/lilo.conf

–t option tests the configuration; it doesn’t write anything to the boot sector

–v option produces verbose output when lilo is run. This is useful with the –t option to see how your changes will work out

–b bootdev option specifies a boot device, overriding the boot= option in lilo.conf
it’s possible to specify an alternate init program. A common technique is to use a regular shell program like bash in place of init. You do so at the boot: prompt like this:
boot: linux init=/bin/sh
usual location for GRUB’s configuration file
/boot/grub/menu.lst

Some distributions use grub.conf
GRUB Configuration File
# grub.conf/menu.lst
#
# Global Options:
#
default=0
timeout=15
splashimage=/grub/bootimage.xpm.gz
#
# Kernel Image Options:
#
title Fedora (2.6.25)
root (hd0,0)
kernel /vmlinuz–2.6.25 ro root=/dev/hda5 mem=2048M
initrd /initrd–2.6.25
title Debian (2.6.26–experimental)
root (hd0,0)
kernel (hd0,0)/bzImage–2.6.26–experimental ro root=/dev/hda6
#
# Other operating systems
#
title DOS
rootnoverify (hd0,1)
chainloader +1
LILO Configuration File
# lilo.conf
#
# Global Options:
#
boot=/dev/hda
prompt
timeout=150
default=fedora
lba32
vga=normal
root=/dev/hda5
read–only
#
# Kernel Options (may have multiple):
#
image=/boot/vmlinuz–2.6.25
label=fedora
initrd=/boot/initrd–2.6.25
append=”mem=2048M”
image=/boot/bzImage–2.6.26–experimental
label=debian
root=/dev/hda6
#
# Other Operating Systems Options (may have multiple):
#
other=/dev/hda2
label=dos
GRUB numbers drives so that instead of /dev/hda,
GRUB uses (hd0)

/dev/hdb is hd1

GRUB doesn’t distinguish between PATA, SATA, and SCSI drives, so on a SCSIonly system, the first SCSI drive is (hd0)

On a mixed system, ATA drives normally receive
the lower numbers, although this isn’t always the case
GRUB’s drive mappings can be found in the

GRUB separates partition numbers from drive numbers with
GRUB’s drive mappings can be found in the /boot/grub/device.map file

GRUB separates partition numbers from drive numbers with comma, as in (hd0,0) for the first partition on the first disk
GRUB defines its own root partition
GRUB’s root partition is the partition in which GRUB’s configuration file (menu.lst or grub.conf) resides
GRUB Options
default=

timeout=

splashimage=
default=
tells GRUB which OS to boot If you want to
boot the second listed operating system, use default=1, and so on through all your OSs.

timeout=
defines how long, in seconds, to wait for user input before booting the default operating system.

splashimage=
oints to a graphics file that’s displayed as the
background for the boot process.
GRUB Per–Image Options

title

root
title line begins a per–image stanza and specifies the label to display when the boot loader runs.

root option
specifies the location of GRUB’s root partition
GRUB Per–Image Options
kernel

initrd
kernel setting
describes the location of the Linux kernel as well as any kernel options that are to be passed to it.

you can specify devices using GRUB’s syntax, such as kernel (hd0,5) /vmlinuz ro root=/dev/hda5

initrd option
specify an initial RAM disk
GRUB Per–Image Options
rootnoverify

chainloader
rootnoverify
is similar to the root option except that GRUB won’t try to access files on this partition. It’s used to specify a boot partition for OSs for which GRUB can’t directly load a kernel, such as DOS and Windows.

chainloader
tells GRUB to pass control to a nother boot loader. Typically, it’s passed a +1 option to load the first sector of the root partition
command for installing GRUB
grub–install
# grub–install /dev/hda

# grub–install ‘(hd0)‘
kernel ring buffer (def)
certain Linux kernel and module log info in what is called kernel ring buffer
inspect the content of the kernel ring buffer
dmesg

This command generates a lot of output

# dmesg | less
# dmesg > boot.messages
/var/log/dmesg
Many Linux distributions store the kernel ring buffer to /var/log/dmesg soon after the system boots.
system logger
Another source of logging information is the system logger (syslogd). The most useful
syslogd file to look at is usually /var/log/messages, but /var/log/syslog and other log files in /var/log can also hold helpful information.
Debian uses a daemon called ________ that, by default, logs any messages
that go to _____________________
Debian

/dev/console to the /var/log/boot
Fedora and Red Hat use _________ service to log information to __________
Fedora and Red Hat use syslogdservice to log information to /var/log/boot.log
The Boot Process
1. System is powered, a special hardware circuit causes the CPU to look at a predetermined address and execute the code (BIOS reside in this location)
2. BIOS checks hardware, configs hardware, looks for boot sector ( boot sector contains the boot loader).
3. Boot loader takes over from the BIOS
4. Boot loader tries to find a kernel, load it in memory and execute
5. Once linux kernel takes over, initializes devices, mounts root partition, loads and executes initial program by default, this is the program /sbin/init.
6. The initial program gets the process ID (PID) of 1 because it’s the first program to run on the system. Assuming that /sbin/init is the initial program, it reads a file called
/etc/inittab to determine what other programs to run.
What is the default program that the Linux kernel executes
/sbin/init
runlevels
Linux relies on runlevels to determine what features are available. Runlevels are numbered from 0 to 6, and each one is assigned a set of services that should be active
What options should b e passed to the kernel by the boot loader in ourder to boot in a single–user mode
1
S
s
single

etters S and s are synonymous with runlevel 1
If you run into peculiar runlevel numbers, consult ___________
/etc/inittab—it defines them and often contains comments explaining the various runlevels.
runlevel 0
Transitional runlevel
used to shift the system from one state to another.
Specifically it shutdowns the system.
runlevel 1,s,S
Single–used mode
What services if any are started at this runlevel varies by distribution.
Typically used for low–level system maintenance that may be affected by normal operation (such as partition re–sizing)
runlevel 2
On Debian its a full multi–user mode with X running and a graphical login
runlevel 3
Fedore, Mandriva, Red Hat full multi0user mode with a console login screen
runlevel 4
usually undefined and available for customization
runlevel 5
Fedora, Mandriva, Red Hat usually treat is as runlevel3 with the addition of having X run with an XDM (graphical) login
runlevel 6
used to reboot the system
This runlevel is also a transitional runlevel
Way to affect what programs run when you enter a new runlevel
add or delete entries in your /etc/inittab file
/etc/event.d
Linux distributions are moving away from /etc/inittab as a startup control file. The new system uses entries in /etc/event.d to control init’s startup sequence. Most distributions still use /etc/inittab to specify the default runlevel, though
Basics of the /etc/inittab File
/etc/inittab follow a simple format

id:runlevels:action:process

id
sequence of 1–4 chars that ids the func
runlevles
list of runlelvel for which this entry applies (345 means applicable to 3, 4, 5 runlevel(
action
tells init how to treat the preocess – wait, respawn
process
the process to run for this entry
The part of /etc/inittab that tells init how to handle each runlevel looks like this
# grep “rc [0–6]“ /etc/inittab
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
/etc/init.d/rc or /etc/rc.d/rc script
performs the crucial task of running all the
scripts associated with the runlevel.
where are the runleve l–specific scripts stored
/etc/rc.d/rc?.d, /etc/init.d/rc?.d, /etc/rc?.d
? is the runlevel number

rc passes the start parameter to all the scripts with names that begin with a capital
S and the stop parameter to all the scripts with names that begin with a capital K.
start the smb (Samba) server
Run them with the start option,
as in /etc/init.d/smb start to start the smb (Samba) server

Other useful options are stop, restart, and status
chkconfig cmd
To list the services and their applicable runlevels with chkconfig, use the ––list option

# chkconfig ––list
pcmcia 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nfs–common 0:off 1:off 2:off 3:on 4:on 5:on 6:off
xprint 0:off 1:off 2:off 3:on 4:on 5:on 6:off
setserial 0:off 1:off 2:off 3:off 4:off 5:off 6:off
chkconfig option to list a specific service, you can specify its name:
# chkconfig ––list nfs–common
nfs–common 0:off 1:off 2:off 3:on 4:on 5:on 6:off
chkconfig option to modify the runlevels in which a service runs, use a command like this
chkconfig ––level 23 nfs–common on
command adds the nfs–common script to those managed by chkconfig
# chkconfig ––add nfs–common
ntsysv utility
interactive text–mode tool. It was created by Red Hat and used mainly for it
If you want to change the default runlevel for the next time you boot your system, edit the
initdefault line in /etc/inittab and change the runlevel field to the value that you want.
If your system is up and running, you can determine your runlevel information with the __________cmd
runlevel

# runlevel
N 2

N, this means the system hasn’t switched runlevels since booting
changing runlevels on a running system list cmd
init (or telinit),
shutdown,
halt,
reboot,
poweroff
init process
the first process run by the Linux kernel, but you can also use it to have the system reread the /etc/inittab
reboot the system using init
set runlevel to 6

#init 6
shutdown command
better to use in multi–user environment when you wnat to reboot, shut down or swithc to single–user mode
shutdown now
shutdown +m
shutdown –r
shutdown –H
shutdown –P
shutdown –c
now – shutdown is issued right away

+m – m minutes in the future

–r – reboots the system

–H – terminates operation but doesnt power off

–P – powers off

–c – cancels shutdwn
shutdown system with a warning message
# shutdown –h +15 “system going down for maintenance”
Vi Modes
Command mode
Ex mode
Insert mode
Vi command mode
aaccepts commands which are usually a single letter
Vi command ex mode
use to manipulate files
to enter ex mode type : followed directly by the name of the ex mode command
Vi insert mode
allows you to enter text
cmd to load vi and launc a particular file in it
vi lili.conf
Vi yank (term)

cmd to enter yank mode
yank is used for referrencing copy in Vi

cmd to enter yank mode yy preceded by the number of lines you want to copy
4yy – copies 4 lines fo the current cursor position down
Vi paste cmd

Cmd to enter insert mode but overrigth text

Cmd to enter insert mode but without overrigthing text
Vi paste cmd – p

Cmd to enter insert mode but overrigth text – R

Cmd to enter insert mode but without overrigthing text – i
Vi cmd to save file
What ~ does in commande mode
:wq or ZZ

What ~ does in commande mode, changes case
Position the cursor on the first character you want to change, and press ~ repeatedly until the task is done
Vi cmd

to undo any chage

open text

search
to undo any chage – u in command mode

open text – o

search – / im command mode followed by search term
Vi cmd to
change text

go to a line

replace globally
change text – c
changes text from within command mode

go to a line – G
brings you to a line that you specify

replace globally
type :%s/original/ replacement, where original is the original string and replacement is its replacement. Change % to a starting line number
Vi cmd
brings the curso to teh top of the screen
brings the curso to the bottom line of the screen
brings the curso to the top of the screen – H
brings the curso to the bottom line of the screen – L
Vi cmd to
save changes to a file

edit a new file
save changes to a file
type :w in command mode

edit a new file – e:
This :e /etc/inittab will load /etc/inittab
(Vi wont load the new file until the existent one is saved)
Vi cmd to
execute an external cmd

quit
execute an external cmd – :!
:!ls runs ls

quit – :q
IRQs
0
1
2
3
4
0 – System timer – Reserved for internal use.

1 – Keyboard – Reserved for keyboard use only.

2 – Cascade for IRQs 8–15

3 – Second RS–232 serial port (COM2: in Windows) – May also be shared by a fourth RS–232 serial port.

4 First RS–232 serial port (COM1: in Windows) – May also be shared by a third RS–232 serial port.
IRQ
5
6
7
8
5 – Sound card or second parallel port (LPT2: in Windows)
6 – Floppy disk controller Reserved for the first floppy disk controller.
7 – First parallel port (LPT1: in Windows)
8 – Real–time clock Reserved for system clock use only.
IRQ
8
9
10
11
8 Real–time clock Reserved for system clock use only.
9 Open interrupt
10 Open interrupt
11 Open interrupt
IRQ
12
13
14
15
12 – PS/2 mouse
13 – Math coprocessor Reserved for internal use.
14 – Primary ATA controller – The controller for ATA devices such as hard drives; typically /dev/hda and /dev/hdb under Linux.
15 – Secondary ATA controller – The controller for more ATA devices; typically /dev/hdc and /dev/hdd under Linux.
Once a Linux system is running, you can explore what IRQs are being used for various purposes by
examining the file /proc/interrupts

$ cat /proc/interrupts
/proc info
/proc filesystem is a virtual filesystem—it doesn’t refer to actual files on a hard disk, but to kernel data that’s convenient to represent using a filesystem.
The files in /proc provide information about the hardware, running processes, and so on. Used by many utils
/proc/interrupts file lists IRQs that are in use by Linux but ___
/proc/interrupts file lists IRQs that are in use by Linux, but Linux doesn’t begin using an IRQ until the relevant driver is loaded. This may not happen until you try to use the hardware. Thus, the /proc/interrupts list may not show all the interrupts that are configured on your system.
I/O Address
COM1
COM2
COM3
COM4
port

irq i/o address


COM1 4 0x03f8


COM2 3 0x02f8


COM3 4 0x03e8


COM4 3 0x02e8

i/o adresses
LPT1
LPT2
A:
B:
port

irq i/o address


LPT1 7 0x0378–0x037f


LPT2 5 0x0278–0x027f


A:

What linux device corresponds to
COM1, COM2, COM3, COM4
LPT1, LPT2
A:, B:
COM1,2,3,4 – /dev/ttyS0 – /dev/ttyS3
LPT1,2 – /dev/lp0 – /dev/lp1
A:/B: – /dev/fd0 – /dev/fd1
Once a Linux system is running, you can explore what I/O addresses are being used by examining the contents of what file
/proc/ioports file

$ cat /proc/ioports
DMA (abbr + expl)
Direct memory addressing (DMA) is an alternative method of communication to I/O ports. Rather than have the CPU mediate the transfer of data between a device and memory, DMA permits the device to transfer data directly, without the CPU’s attention. The result can be lower CPU requirements for I/O activity, which can improve overall system performance.
DMA channels are in use on your system, examine the
/proc/dma file

$ cat /proc/dma
2: floppy
4: cascade
CHS geometry
LBA
cylinder/head/sector (CHS) geometry
logical block addressing
sysfs virtual filesystem
sysfs virtual filesystem mounted at /sys, exports information about devices so that "user space" utilities can access the information
user space program

kernel space code
is one that runs as an ordinary program, whether it runs as an ordinary user or as root

kernel space code – runs as part of the kernel, typically only kernel can communicate directly with hardware
HAL Daemon (abbr + expl)
The Hardware Abstraction Layer (HAL) Daemon, or hald, is a user space program that runs at all times (that is, as a daemon) that provides other user space programs with information about available hardware
D–Bus
Desktop Bus (D–Bus) provides a further abstraction of hardware information access. Like hald, D–Bus runs as a daemon. D–Bus enables processes to communicate with each other as well as to register to be notified of events, both by other processes and by hardware (such as the availability of a new USB device).
udev
Linux creates device nodes as conventional files in the /dev directory tree.
existence of hotplug devices and various other issues have motivated the creation of
udev:
a virtual file system, mounter at /dev
create dynamic device files as drivers are loaded and unloaded
how can you configure udev virtual filesystem
you can configure udev through file in /etc/udev
setpci utility
use to directly query and adjust PCI devices' config
lspci system
lspci command is used for this purpose; it displays all information about the PCI busses on your system and all devices connected to those busses
Options for lspci
–v

–n

–nn
–v Increases verbosity of output. This option may be doubled (–vv) or tripled (–vvv) to produce yet more output

–n Displays information in numeric codes rather than translating the codes to manufacturer and device names.

–nn Displays both the manufacturer and device names and their associated numeric codes.
Options for lspci
–x

–b

–t
–x Displays the PCI configuration space for each device as a hexadecimal dump. This is an extremely advanced option. Tripling (–xxx) or quadrupling (–xxxx) this option displays information about more devices

–b Shows IRQ numbers and other data as seen by devices rather than as seen by the kernel.

–t Displays a tree view depicting the relationship between devices
Options for lspci
–s [[[[domain]:] bus]:][slot][.[func]]

–d [vendor]:[device]

–i file
–s [[[[domain]:] bus]:][slot][.[func]] – Displays only devices that match the listed specification. This can be used to trim the results of the output

–d [vendor]:[device] – Shows data on the specified device.

–i file – Uses the specified file to map vendor and device IDs to names. (The default is /usr/share/misc/pci.ids.)
Options for lspci

–m

–D

–m

––version
–m – Dumps data in a machine–readable form, intended for use by scripts. A single –m uses a backward–compatible format, whereas doubling (–mm) uses a newer format

–D – Displays PCI domain numbers. These numbers normally aren’t displayed.

–m – Performs a scan in bus–mapping mode, which can reveal devices hidden behind a misconfigured PCI bridge. This is an advanced option that can be used only by root.

––version – Displays version information.
kernel modules (aka kernel drivers)
Hardware in Linux is handled by kernel drivers, many of which come in the form of kernel modules. These are stand–alone driver files, typically stored in the /lib/modules directory tree, that can be loaded and unloaded to provide access to hardware. Typically, Linux loads the modules it needs when it boots, but you may need to load additional modules yourself
/lib/modules directory
kernel modules are typically stored in the /lib/modules directory
lsmod cmd
You can learn about the modules that are currently loaded on your system by using lsmod
Linux enables you to load kernel modules with two programs:
insmod

modprobe.
insmod prog

modprobe prog
insmod program inserts a single module into the kernel. This process requires you to have already loaded any modules on which the module you’re loading relies

modprobe program, by contrast, automatically loads any depended–on modules and so is generally the preferred way to do the job.
What command loads the floppy.ko module, which you must specify by filename.
Modules have module names, too, which are usually the same as the filename but without the extension, as in floppy for the floppy.ko file. Unfortunately, requires the full module name.
# insmod /lib/modules/2.6.26/kernel/drivers/block/floppy.ko
modprobe options

–v

–C filename

–n
–v or ––verbose
tells modprobe to display extra information about its operations. Typically, this includes a summary of every insmod operation it performs

–C filename
since modprobe use a config file we can change it with this option

–n or ––dry–run
causes modprobe to perform checks and all other operations except the actual module insertions. You might use this option in conjunction with –v to see what modprobe would do without loading the module.
What config. file modprobe uses?
/etc/modprobe.conf.
You can change the file by passing a new file with the –C filename option, as in modprobe –C /etc/mymodprobe.conf floppy
modprobe options

–r

–f

–l

––show–depends
–r or ––remove
reverses modprobe’s usual effect; it causes the program to remove the specified module and any on which it depends

–f or ––force
force the module loading even if the kernel version doesn’t match what the module expects

–l or ––list option
list of available options whose names match the wildcard you specify. For instance, typing modprobe –l v*

––show–depends
shows all the modules on which the specified module depend
lsmod program

rmmod command
shows how much memory each module consumes

rnmod
unload a kernel module
# rmmod floppy
rmmod options
–v

–f

–w
–v or ––verbose option causes rmmod to display some extra information about what it’s doing

–f or ––force option forces module removal even if the module is
marked as being in use.

–w or ––wait option causes rmmod to wait for the module to become unused, rather than return an error message, if the module is in use. Once the module is no longer being used
lsusb utility
simple use of this program with no options reveals basic information about your USB devices:

$ lsusb
Bus 003 Device 008: ID 0686:400e Minolta Co., Ltd
Bus 003 Device 001: ID 0000:0000
lsusb utility options
–v

–s [[bus]:][devnum]

–d [vendor]:[product]
–v option produces extended information about each product

–s [[bus]:][devnum] option restricts output to the specified bus and device number.

–d [vendor]:[product]
You can limit output to a particular vendor and product by using the –d [vendor]:[product] option. The vendor and product are the codes just after
ID on each line of the basic lsusb output
lsusb utility options
–D filename

–t

––version
–D filename displays information about the device that’s accessible via filename, which should be a file in the /proc/bus/usb directory tree.

–t option displays the device list as a tree, so that you can more easily see what devices are connected to specific controllers.

––version option displays the version of the lsusb utility and exits.
This directory provides a low–level interface to USB devices (what directory)
/proc/bus/usb
usbmgr package
is a program that runs in the background to detect changes on the USB bus. When it detects
changes, it loads or unloads the kernel modules that are required to handle the devices.

/etc/usbmgr to handle specific devices
/etc/usbmgr/usbmgr.conf to control the overall configuration
Hotplug package
relies on kernel support added with the 2.4.x kernel series.
system uses files stored in /etc/hotplug to control the configuration of specific USB devices
/etc/hotplug/usb.usermap contains a database of USB device IDs and pointers to scripts
/etc/hotplug/usb contains scripts that are run when devices are plugged/unpligged
scsi naming system hard drivers
scsi naming system cd rom
/dev/nstx
/dev/scdx
Under Linux, primary and extended partitions are assigned numbers from
1 to 4
/dev/hda1 – first primary partition on the first PATA
/dev/sdb3 – third primary partition on the second SCSI disk, respectively
Logical partitions are assigned numbers from
up, as in /dev/hda5 or /dev/sdb5. These numbers are assigned sequentially, and numbers aren’t ordinarily skipped; if a disk has
/dev/hda6, then /dev/hda5 also exists.
partition type codes
used mainly in x86
0x06 – FAT
0x82 – Linux swap partition
0x83 – Linux filesystem partition
for the most part Linux ignores partition type codes, exception is during installation
and extended partitons codes 0x05 and 0x06
cmd to examine the partition table on a disk
disk –l /dev/hdb
As root
change hdb to an appropriate device identifier
GNU Parted
To manipulate non–x86 partitions supports x86, Macintosh, and several other types of
partition tables.
GPT system (abbr)

LVM
Globally Unique Identifier (GUID) Partition Table (GPT) system

logical volume management
alternative to partitions for some functions is logical volume management
To use LVM, you set aside one or more partitions and assign them partition type codes of
What utilities can you use to manage LMV?

then to access the logical volume using names assigned to them in what folder
0x8e

pvcreate, vgcreate, lvcreate, and lvscan,

/dev/mapper folder

LMV enables you to easily resize your logical volumes without worrying about the position or size of surrounding partitions
Linux, though, doesn’t use drive letters
instead, Linux uses a unified directory tree. Each partition is mounted at a mount point in that tree. A mount point is a directory that’s used as a way to access the filesystem on the partition, and mounting the filesystem is the process of linking the filesystem to the mount point
swap partition (mount point)
1.5–2 times system RAM size

Serves as an adjunct to system RAM; is slow, but enables the computer to run more or larger programs
/home partition (mount point)
Holds users’ data files. Isolating it on a separate partition preserves user data during a system upgrade. Size depends on the number of users and their data storage needs.
/boot partition (mount point)
Holds critical boot files. Creating it as a separate partition lets you circumvent limitations of older BIOSs and boot loaders on hard disks over 8GB
/usr partition (mount point)

/usr/local partition (mount point)
/usr – Holds most Linux program and data files

/usr/local – Holds Linux program and data files that areunique to this installation, particularly those that you compile yourself
/opt partition (mount point)
Holds Linux program and data files that are associated with third–party packages, especially commercial ones.
fdisk
traditional Linux tool for disk partitioning

fdisk /dev/hda
Display the current partition table
Display the help for fdisk
Create a partition
Delete a partition
p (once fdisk is started)
m (once fdisk is started)
n
d
fdisk –l /dev/hda
display current partition table without going in fdisk
What command to use in fdisk to change partition type?
t
when fdisk creates a partition it assigns a type of code
t allows you to change the partition type of code
fdisk list partition types

fdisk make a partition bootable

fdisk quit

fdisk commit ch
agnes
l
at the main fdisk prompt to see a list of the partition types

a
makes a partition bootable

q
quit

w
commits changes
low–level format a floppy disk
you must use the fdformat command, as in fdformat /dev/fd0. This command cannot be used on a hard disk.
Ext2fs
Ext2fs – Second Extended File System (ext2fs or ext2)

traditional Linux native filesystem
good choice for small boot partition
non–journaling
type code ext2
Ext3fs
Ext3fs – third extended file system (ext3fs or ext3)

Ext2fs with a journal added which allows it to recover from power outages
type code ext3
Ext4fs
Ext4fs – Fourth Extended File System

adds ability to work with large files up to 32tb

type code ext4de/ext4
ReiserFS
designed as a journaling filesystem for Linux
good for handling filesystems with a lot of small files

type code – reiserfs
JFS
Journaled File System by IBM for OS/2
technically sophisticated journaling filesystem

type code – jfs
XFS
Extents File System (XFS)

robust, fast and flexible but since it was designed for IRIX OS soem features are not fully supported on Linux

type code xfs
FAT
File Allocation Table (FAT)

linux automatically detects the FAT size

type code msdos
type code to support long windows names vfat
NTFS
New Technology File System (NTFS)

Linux support for NTFS is rudimentary, as of 2.6.x kernel, linux cat read NTFS and can overwrite existing files, but Linux kernel can't write new files
NTFS–3G driver
This is a read/write NTFS driver that resides in user space rather than in kernel space. It’s used as the default NTFS driver by some Linux distributions.
HFS and HFS+
Hierarchical File System (HFS) by Apple
Linux fully support HFS
ISO–9660
standard filesystem for CD–ROMs
Level 1 is similar to the original FAT – supports only 8.3 filenames
Levels 2 and 3 add support for longer 32–character filenames

type code iso9660
Rock Ridge extensions
are a series of extensions to ISO–9660 to enable it to support Unix–style long filenames, permissions, symbolic links, and so on. If a
disc includes Rock Ridge extensions, Linux will automatically detect and use them
Joliet
much like Rock Ridge, as an extension to ISO–9660, but it’s technically a separate filesystem

Linux supports Joliet as part of its iso9660 driver; if a disc contains Joliet but not Rock Ridge, Linux uses the Joliet filesystem.
UDF
Universal Disc Format (UDF)
next–generation filesystem for optical discs used on DVD–ROM
Creating a Filesystem cmd
# mkfs –t ext3 /dev/hda6
Creating a Filesystem for ext2 and ext3 filesystems cmd

–m option
mke2fs

–m percent, which sets the reserved–space percentage.
–m 0 also makes sense on removable disks
ext2fs/ext3fs reserved–space percentage defaults to 5 percent
tool for creating FAT systems

–F fat–size option
mkdosfs, but it’s often linked to the mkfs.msdos and mkfs.vfat names,

–F fat–size option
set size of the FAT to 12, 16 or 32
swap partition
Linux treats as an extension of memory
type code 0x82
What file linux uses to define which partitions to use as swap space
/etc/fstab
mkswap command
mkswap /dev/hda7

swap space does require preparation similar to that for creation of a filesystem this task is accomplisehd with the mkswap cmd
use the swap space, you must activate it with the ???? cmd
# swapon /dev/hda7

To permanently activate swap space, you must create an entry for it in /etc/fstab
Obtaining Filesystem Information cmd
dumpe2fs
gets info about ext2 and ext3

dumpe2fs [options] device
Obtaining Filesystem Information cmd
(for xfs)
xfs_info

# xfs_info /dev/sda7

Most other filesystems lack an equivalent to dumpe2fs, but XFS provides something with at least some surface similarities: xfs_info
xfs_metadump
program copies the filesystem’s metadata to a file

xfs_metadump /dev/sda7 ~/dump–file

copies the metadata to ~/dump–file, this is not a backup
tune2fs program
enables you to change many of the filesystem parameters that are
reported by dumpe2fs.

tune2fs [options] device
tune2fs option
–c mounts
–i interval
–c mounts option
ext2fs and ext3fs require a periodic disc check fsck, whit this option you adjust the max number of time the disk may be mounted without a check

–i interval
Periodic disk checks are required based on time as well, with this option we set the interval between checks
tune2fs option
–j option
–m percent
–j option
journal to the filesystem, effectively converting an ext2 filesystem into an ext3 filesystem

–m percent
sets the percentage of disk space that’s reserved for use by root
xfs_admin command
rough equivalent of tune2fs
xfs_admin option
–j option

–l and –u options

–L label or –U uuid option
–j option
enables version 2 log (journal) format, which can improve performance in some situations.

–l and –u options
obtain the filesystem’s label (name) and universally unique identifier (UUID), respectively

–L label or –U uuid option
You can change the filesystem’s label or UUID
sets the name of the filesystem on /dev/sda7 to av_data
# xfs_admin –L av_data /dev/sda7
writing all SBs
new label = “av_data”
debugfs.
In addition to reviewing and changing filesystem flags with dumpe2fs and tune2fs, you can interactively modify a filesystem’s features using debugfs. This program provides the abilities of dumpe2fs, tune2fs, and many of Linux’s normal file–manipulation tools all rolled into one

# debugfs /dev/hda11
debugfs:
debugfs option
show_super_stats

stat filename,
show_super_stats or stats
produces superblock information, similar to what dumpe2fs displays.

stat filename
display the inode data on a file or directory
debugfs option
undelete inode name

lsdel
undelete inode name
undelete a file, where inode is the inode number of the deleted file and name is the filename you want to give to it.

lsdel or list_deleted_inodes
list of deleted inodes
debugfs option
write internalfile external–file

list_requests, lr, help, or ?

quit
write internalfile external–file
extract a file from the filesystem, where internal–file is the name of a file in the filesystem you’re manipulating and external–file is a filename on your main Linux system

list_requests, lr, help, or ?
produces a summary of available commands

quit
exits from the program
xfs_db cmd
closest XFS equivalent to debugfs is called xfs_db.
fsck
tool for verifying a filesystem's integrity and for correcting any problems that may exist

fsck [–sACVRTNP] [–t fstype] [––] [fsck–options] filesystems
fsck options
–A
–C
–V
–A option causes fsck to check all the filesystems marked to be checked in /etc/fstab.

–C option displays a text–mode progress indicator of the check process.

–V option produces verbose output of the check process
fsck options
–t fstype

–N
Normally, fsck determines the filesystem type automatically. You can force the type with the –t fstype flag, though

–N option tells fsck to display what it would normally do without actually doing it
fsck command passes options it doesn’t understand, or those that follow a double dash (––), to the underlying check program. Common options:
–a
–p
–r
–f
–a or –p
perform automatic check

–r
perform an interactive check

–f
force a full filesystem check even if the filesystem initially appears to be clean
df command
df displays the amount of disk space available on the filesystem containing each file name argumen

df [options] [files]

$ df
Filesystem 1K–blocks Used Available Use% Mounted on
/dev/sdb10 5859784 4449900 1409884 76% /
/dev/sdb12 2086264 991468 1094796 48% /opt
df option
–a
–h
–H
–k/–m
–a or ––all option
includes pseudo filesystems with a size of 0 in the output. These filesystems may include /proc, /sys, /proc/bus/usb, and others.

–h or ––human–readable option
causes df to scale and label its units; for instance, instead of reporting a partition as having 5859784 blocks, it reports the size as
5.6G (for 5.6GB).

–H and ––si options
causes df to scale and label its units, but they use power–of–10

–k (––kilobytes) and –m (––megabytes) options
force output in their respective units.
df option
–i
–l
–T
–t
–i or ––inodes option
By default, df summarizes available and used disk space. You can instead receive a report on available and used inodes

–l or ––local option
causes df to omit network filesystems. This can speed up operation

–T or ––print–type option
adds the filesystem type to the information df displays
df option
–t fstype
–x fstype
–t fstype or ––type=fstype option
displays only information about filesystems of the specified type

–x fstype or ––exclude–type=fstype
excludes filesystems of the specified type from the report
du cmd
shows disk usage by individual directories and files

du [options] [directories]
du option
–a
–c
–h
–a or ––all option
Ordinarily, du reports on the space used by the files in directories but not the space used by individual files, this option causes du to report on individual files as well

–c or ––total option
causes du to add a grand total to the end of its output

–h or ––human–readable
causes du to scale and label its units
–H and ––si options have a similar effect but they use powerof–10
–k (––kilobytes) and –m (––megabytes) options force output in their respective units
du option
–l

––max–depth=n

–s

–x
–l or ––count–links option
Ordinarily, du counts files that appear multiple times as hard links only once. This reflects true disk space used, but sometimes you may want to count each link independently

––max–depth=n option
limits the report to n levels

–s or ––summarize option
If you don’t want a line of output for each subdirectory in the tree which limits the report to those files and directories you specify on the command line

–x or ––one–file–system option
limits the report to the current filesystem. If another filesystem is mounted within the tree you want summarized, its contents aren’t included in the report.
Cmd to discover which of your users is consuming the most disk space in /home.
# du –s /home/*
12
persistently mount across reboots by editing
/etc/fstab file
mount syntax
[–alrsvw] [–t fstype] [–o options] [device] [mountpoint]
mount options
–a
–r
–v
–a parameter causes mount to mount all the filesystems listed in the /etc/fstab file

–r parameter causes Linux to mount the filesystem read–only, even if it’s normally a read/write filesystem.

–v produces verbose output—the program provides comments on operations as they occur.
mount options
–w
–t fstype
–L label and –U uuid options
–w parameter causes Linux to attempt to mount the filesystem for both read and write operations.

–t fstype parameter to specify the filesystem type

–L label and –U uuid options tell mount to mount the filesystem with the specified label or UUID, respectively.
mount options
device
mountpoint
device is the device filename associated with the partition or disk device, such as /dev/hda4, /dev/fd0, or /dev/cdrom

mountpoint is the directory to which the device’s contents should be attached.
command mounts the contents of /dev/sdb7 on /mnt/shared, auto–detecting the filesystem type and using the default options
# mount /dev/sdb7 /mnt/shared
only root may issue a mount command; however, if ______ specifies the user, users, or owner option, an ordinary user may mount a filesystem using a simplified syntax in which only the device or mount point is specified, but not both.
if /etc/fstab specifies the user, users, or owner option, an ordinary user may mount a filesystem using a simplified syntax in which only the device or mount point is specified, but not both
what cmd to type to mount a CD–ROM if /etc/fstab specifies /mnt/cdrom as its mount point and uses the user, users, or owner option
mount /mnt/cdrom
mount options
defaults
loop
defaults – All – Causes the default options for this filesystem to be used. It’s used primarily in the /etc/ fstab file to ensure that the file includes an options column.

loop – All – Causes the loopback device for this mount to be used. Allows you to mount a file as if it were a disk partition. For instance, mount –t vfat –o loop image.img /mnt/image mounts the file image.img as if it were a disk.
mount options
auto or noauto

user or nouser

users
auto or noauto – All – Mounts or doesn’t mount the filesystem at boot time or when root issues the mount –a command. The default is auto, but noauto is appropriate for removable media. Used in /etc/fstab.

user or nouser – All – Allows or disallows ordinary users to mount the filesystem. The default is nouser

users – All – Similar to user, except that any user may unmount a filesystem once it’s been mounted.
mount options
owner

remount

ro
owner – All – Similar to user, except that the user must own the device file. Some distributions, such as Red Hat, assign ownership of some device files (such as /dev/fd0 for the floppy disk) to the console user, so this can be a helpful option

remount – All – Changes one or more mount options without explicitly unmounting a partition. To use this option, you issue a mount command on an already–mounted filesystem but with remount along with any options you want to change. This feature can be used to enable or disable write access to a partition, for example

ro – All – Specifies a read–only mount of the filesystem. This is the default for filesystems that include no write access and for some with particularly unreliable write support.
mount options
rw

uid=value

gid=value
rw – All read/write filesystems – Specifies a read/write mount of the filesystem.
This is the default for most read/write filesystems.

uid=value – – Sets the owner of all files. For instance, uid=500 sets the owner to whoever has Linux user ID 500.

gid=value – – Works like uid=value, but sets the group of all files on the filesystem. You can find group IDs in the /etc/group file.
mount options
umask=value

dmask=value

fmask=value
umask=value
Sets the umask for the permissions on files. value is interpreted in binary as bits to be removed from permissions on files.

dmask=value
Similar to umask, but sets the umask for directories only, not for files.

fmask=value
Similar to umask, but sets the umask for files only, not for directories.
mount options
conv=code

norock
conv=code – If code is b or binary, Linux doesn’t modify the files’ contents. If code is t or text, Linux auto–converts files between Linux–style and DOS– or Macintosh–style end–of–line characters. If code is a or auto, Linux applies the conversion unless the file is a known binary file format. It’s usually best to leave this at its default value of binary because file conversions can cause serious problems for some applications and file types.

norock – iso9660 – Disables Rock Ridge extensions for ISO–9660 CD–ROMs.

nojoliet – iso9660 – Disables Joliet extensions for ISO–9660 CD–ROMs.
umount cmd
umount [–afnrv] [–t fstype] [device | mountpoint]
umount option
–a
–f
–r
–a option
causes the system to attempt to unmount all the partitions listed in /etc/mtab

–f option
tell Linux to force an unmount operation that might otherwise fail.

–r option
tells umount that if it can’t unmount a filesystem, it should attempt to remount it in read–only mode.
umount option
–t fstype
device
–t fstype option
tells the system to unmount only partitions of the specified type. You can list multiple filesystem types by separating them with commas.

device
You need to specify only the device or only the mountpoint, not both
What file controls how Linux provides access to disk partitions and removable media devices.
/etc/fstab

/etc/fstab file consists of a series of lines that contain six fields each; the fields are separated by one or more spaces or tabs
Sample /etc/fstab File
#device
Mount point (Def)
second column specifies the mount point; in the unified Linux filesystem,
this is where the partition or disk will be mounted. This should usually be an empty directory in another filesystem.
The root (/) filesystem is an exception.
So is swap space, which is indicated by an entry of swap
most important Linux disk partition is

home directories

program files

transient system files

temporary user files

kernel and boot files
root (/) partition

/home

/prog

/var

/temp

/boot
Two major Linux package management tools exist
RPM and Debian packages. (Several less–common
package management systems also exist.)
libraries (def)
software components that can be used by many different
programs.
Libraries help reduce the disk space and memory requirements of complex
programs, but they also require some attention; if that attention isn’t given to them, they
can cause problems by their absence or because of incompatibilities between their and their dependent software’s versions.
Packages (def)
collections of files that are installed on the computer. Packages are usually distributed as single files similar to tarballs or zip
installed file db (def)
Package systems maintain a DB of installed files. The DB includes info about every file installed via the package system
Binary package creation
Both the RPM and Debian package systems provide tools to help create binary packages (those that are installed directly) from source code. This feature is particularly helpful if you’re running Linux on a peculiar CPU; you can download source code and create a binary package even if the developers didn’t provide explicit support for your CPU. Creating a binary package from source has advantages over compiling software from source in more conventional ways, because you can then use the package management system to track dependencies, attend to individual files, and so on.
convention for naming RPM packages

packagename–a.b.c–x.arch.rpm
packagename – name of package
x – build number(release number) – minor changes
a.b.c – version number – assigned by author
arch – architecture – code for package architecture
packagename arch codes
packagename–a.b.c–x.arch.rpm
packagename–a.b.c–x.arch.rpm
arch is code for the
package’s architecture

i386 for 80386 onward
i586/i686 for Pentiums or above
ppc for PowerPC CPU
x86_64 for x86–64 platforms
Yum (abbr and def)
Yum
Yellow Dog Updater Modified
RPM meta–packagers
rpm Command Set
main RPM utility program is known as rpm. Use this program to install or upgrade a package at the shell prompt

rpm [operation][options] [package–files|package–names]
rpm operation
–i
–U
–F or ––freshen
–i
installs a packages; system must not contain packge of the same name
–U
install a new package or upgrades an existing one
–F or ––freshen
upgrades a package only if an earlier version already exists
rpm operation
–q
–V or ––verify
–e
–q
Quarries a package – finds if a package is installed, what file it contains
–V or ––verify
Verifies a package – checks that its files are present
–e
Uninstalls a packages
rpm operations
–b
––rebuild
––rebuilddb
–b
builds a binary package given a src code and config files
––rebuild
builds a binary package given a RPM source
––rebuilddb
rebuilds the RPM DB to fix errors
rpm options
––root dir
––force
––root dir
used with any operation
modifies the linux system having a root folder located at dir
––force
used with operation –i. –U, –F
forces installation of a package even when it means overwriting existing files or packages
rpm options
–h or ––hash
–v
–h or ––hash
used with operation –i. –U, –F
Displays a series of hash marks # to indicate progress

–v
used with operation –i. –U, –F
used with –h option to produce a uniform number of # for each page
rpm options
––nodeps
––test
–p package–file
––nodeps
used with operation –i. –U, –F, –e
Specifies that no dependency checks are performed

––test
used with operation –i. –U, –F
Checks for dependencies, conflicts and other problems without actually installing the package
–p package–file
used with operation –q
queries the uninstalled RPM package file
rpm options
––prefix path
–a or ––all
–f file or ––file file
––prefix path
used with operation –i, –U, –F
Sets the installation dir to path

–a or ––all
used with operation –q, –V
Queries or verifies all packages

–f file or ––file file
used with operation –q, –V
Queries or verifies the package that owns the file
rpm options
–i
–R or ––requires
–l or ––list
–i
used with operation –q
displays package info

–R or ––requires
used with operation –q
displays the packages and files on which this one depends

–l or ––list
used with operation –q
Displays the files contained in the package
Verify that the package is installed with what cmd
rpm –qi samba–server
RPM files are actually modified _____ archives
RPM files are actually modified cpio archives.
Converting RPM files into cpio files and retrieve individual files is easy use the
rpm2cpio program

rpm2cpio samba–server–3.0.25b–4.5mdv2008.0.src.rpm➦
> samba–server–3.0.25b–4.5mdv2008.0.cpio
Cmd sequence for
1)convertin RPM package to cpio file
2)extracting data from the cpio file
$ rpm2cpio samba–server–3.0.25b–4.5mdv2008.0.src.rpm samba–server–3.0.25b–4.5mdv2008.0.cpio
$ cpio –i ––make–directories < samba–server–3.0.25b–4.5mdv2008.0.cpio

or pipe them
$ rpm2cpio samba–server–3.0.25b–4.5mdv2008.0.src.rpm | cpio –i ––make–directories
Using Yum
one of several meta–packagers – it enables you to easily install a package and all its dependencies using a single cmd line

yu, [options] [cmd] [package...]
Common yum cmd
install
update
install – install 1 or more packages by package name
update – updates the specified package to the latest available version (if no packages are specified, yum updates every installed package)
Common yum cmd
check–update
upgrade
remove/erase
check–update – checks to see whether updates are available
upgrade – works like update with the ––obsoletes flag set
remove/erase – deletes a packages from the system; similar to rpm –e, but yum also removes depended–on packages
Common yum cmd
list
provides/whatprovides
search
list – displays info about the package
provides/whatprovides – displays information about packages that provide a specified program or feature (like yum provides samba)
search – searches package names, summaries, packagers and descriptions for a specified keyword
Common yum cmd
info
clean
shell
info – displays info about a package
clean – cleans up the Yum cache directory
shell – enters the yum shell mode, in which you can enter multiple yum cmd one after another
Common yum cmd
resolvedep
localinstall
localupdate
deplist
resolvedep – displays packages matching the specified dependency
localinstall – install the specified local RPM files, using your yum repositories to resolve dependencies
localupdate – updates the system using the specified local RPM files, using your yum repositories to resolve dependencies
deplist – display dependencies of the specified package
yumdownloader
If you don’t want to install the package, but merely want to obtain it, you can use yumdownloader
yumex and kyum
If you prefer to use GUI tools rather than command–line tools, you should be aware that
GUI front–ends to yum exist. Examples include yumex and kyum. You can use the text–mode
yum to install these front–ends, as in yum install kyum.
the main RPM config file location
/usr/lib/rpm/rpmrc
this file sets a variety of options files should not be edited
/etc/rpmrc
~/.rpmrc
/etc/rpmrc
changes here affect RPM configuration on a global scope
~/.rpmrc
change here are on per user bases

Main reason to create such a file is to implement architecture optimization – for instance, to optimize your code for your CPU model by passing approprieate compiler options when you build a soucre RPM into a binary RPM
RPM flas

optflags: athlon –02 –g –march=i686
the main reason to create /etc/rpcrc (global) or ~/.rpmrc (per user) is to implement architecture optimizations by passing apropriate compile options when you build a source RPM into binary ROM

optflags: athlon –02 –g –march=i686

tells RPM to pass the options to the compiler whenever building for the athlon platform
Most default rpmrc files include a series of buildarchtranslate line that cause rpmbuild to use one set of optimization for a whole family of CPU (use with addition to optflags:). How the look
For x86 systems
buildarchtranslate: athlon: i386
buildarchtranslate: i686: i386
buildarchtranslate: i586: i386
buildarchtranslate: i486: i386
buildarchtranslate: i386: i386

These lines tell RPM to translate the athlon, i686, i586, i486, and i386 CPU codes to use the i386 optimizations. This effectively defeats the purpose of any CPU–specific optimizations you create on the optflags line for your architecture, but it guarantees that the RPMs you build will be maximally portable.
cmd to return the CPU type
uname –p
Yum is configured via what file
/etc/yum.conf
addition config files are in
/etc/yum.repos.d/directory
debian packages (notes)
Debian packages are incompatible with RPM packages, but the basic principles of operation are the same across both package types.
You used the dpkg command to install a Debian package

dpkg [options][action] [package–files|package–name]
dpkg actions – dpkg [options][action] [package–files|package–name]
–i or ––install
––configure
–r or ––remove
–i or ––install – Installs a package
––configure – Reconfigures an installed package: runs the post–installation
script to set site–specific options
–r or ––remove Reconfigures an installed package: runs the post–installation
script to set site–specific options
dpkg actions – dpkg [options][action] [package–files|package–name]
–P or ––purge
–p or ––print–avail
–I or –– info
–P or ––purge – removes a package, including config files
–p or ––print–avail – displays information about an installed package
–I or –– info – display information about an uninstalled package file
dpkg actions – dpkg [options][action] [package–files|package–name]
–l pattern or ––list pattern
–L or ––listfiles
–S pattern or ––search pattern
–C or ––audit
–l pattern or ––list pattern – Lists all installed packages whose names match pattern
–L or ––listfiles – Lists the installed files associated with a package
–S pattern or ––search pattern – Locates the package(s) that own the file(s) specified by pattern
–C or ––audit – Searches for partially installed packages and suggests what to do with them
dpkg actions – dpkg [options][action] [package–files|package–name]
––root=dir
–B or ––auto–deconfigure
––force–things
––ignore–depends=package
––root=dir – with all – modifies the linux system using a root directory located at dir
–B or ––auto–deconfigure – used with –r – disables packages that rely on one that is being removbed
––force–things – used with assorted – forces specific actions to be taken
––ignore–depends=package – used with –r, –i – ignores dependency information for the specified package
dpkg actions – dpkg [options][action] [package–files|package–name]
––no–act
––recursive
–G
–E or ––skip–same–version
––no–act – used with –r, –i – Checks for dependencies, conflicts, and other problems without actually installing or removing the package
––recursive – used with –i – Installs all packages that match the package name wildcard in the specified directory and all subdirectories
–G – used with –i – Doesn’t install the package if a newer version of the same package is already installed.
–E or ––skip–same–version – used with –i – Doesn’t install the package if the same version of the package is already installed.
RPM flas

optflags: athlon –02 –g –march=i686
the main reason to create /etc/rpcrc (global) or ~/.rpmrc (per user) is to implement architecture optimizations by passing apropriate compile options when you build a source RPM into binary ROM

optflags: athlon –02 –g –march=i686

tells RPM to pass the options to the compiler whenever building for the athlon platform
Most default rpmrc files include a series of buildarchtranslate line that cause rpmbuild to use one set of optimization for a whole family of CPU (use with addition to optflags:). How the look
For x86 systems
buildarchtranslate: athlon: i386
buildarchtranslate: i686: i386
buildarchtranslate: i586: i386
buildarchtranslate: i486: i386
buildarchtranslate: i386: i386

These lines tell RPM to translate the athlon, i686, i586, i486, and i386 CPU codes to use the i386 optimizations. This effectively defeats the purpose of any CPU–specific optimizations you create on the optflags line for your architecture, but it guarantees that the RPMs you build will be maximally portable.
cmd to return the CPU type
uname –p
Yum is configured via what file
/etc/yum.conf
addition config files are in
/etc/yum.repos.d/directory
debian packages (notes)
Debian packages are incompatible with RPM packages, but the basic principles of operation are the same across both package types.
You used the dpkg command to install a Debian package

dpkg [options][action] [package–files|package–name]
dpkg actions – dpkg [options][action] [package–files|package–name]
–i or ––install
––configure
–r or ––remove
–i or ––install – Installs a package
––configure – Reconfigures an installed package: runs the post–installation
script to set site–specific options
–r or ––remove Reconfigures an installed package: runs the post–installation
script to set site–specific options
dpkg actions – dpkg [options][action] [package–files|package–name]
–P or ––purge
–p or ––print–avail
–I or –– info
–P or ––purge – removes a package, including config files
–p or ––print–avail – displays information about an installed package
–I or –– info – display information about an uninstalled package file
dpkg actions – dpkg [options][action] [package–files|package–name]
–l pattern or ––list pattern
–L or ––listfiles
–S pattern or ––search pattern
–C or ––audit
–l pattern or ––list pattern – Lists all installed packages whose names match pattern
–L or ––listfiles – Lists the installed files associated with a package
–S pattern or ––search pattern – Locates the package(s) that own the file(s) specified by pattern
–C or ––audit – Searches for partially installed packages and suggests what to do with them
dpkg actions – dpkg [options][action] [package–files|package–name]
––root=dir
–B or ––auto–deconfigure
––force–things
––ignore–depends=package
––root=dir – with all – modifies the linux system using a root directory located at dir
–B or ––auto–deconfigure – used with –r – disables packages that rely on one that is being removbed
––force–things – used with assorted – forces specific actions to be taken
––ignore–depends=package – used with –r, –i – ignores dependency information for the specified package
dpkg actions – dpkg [options][action] [package–files|package–name]
––no–act
––recursive
–G
–E or ––skip–same–version
––no–act – used with –r, –i – Checks for dependencies, conflicts, and other problems without actually installing or removing the package
––recursive – used with –i – Installs all packages that match the package name wildcard in the specified directory and all subdirectories
–G – used with –i – Doesn’t install the package if a newer version of the same package is already installed.
–E or ––skip–same–version – used with –i – Doesn’t install the package if the same version of the package is already installed.
Debian higher–level utilities to handle package installation and removal
apt–get
dselect
using apt–cache
intended to provide information about the package cache (Debian package DB)
package cache
in Debian distros the package DB is know as the package cache
cmd in apt–cache to display package information
package statistics
package information – apt–cache showpkg
package statistics – apt–cache stats
how many packages have been installed, dependencies that are recorded
cmd in apt–cache to display unmet dependencies
dependies
locate all packages
unmet dependencies – apt–cache unmet
info about unmet dependencies

display dependencies – apt–cache depends
returns info about all dependencies for the specified package

locate all packages – apt–cache pkgnames
returns only packages that start with the specified string
apt–get (def + syntax)
apt–get is Debian's equivalent to Yum
its a meta packaging tool that enables to perform upgrades

apt–get [options][command] [package–names]

# apt–get update
# apt–get dist–upgrade
Debian–based system include a file that specifies location from which important packages can be obtained
/etc/apt/sources.list
apt–get cmd
update
upgrade
dselect–upgrade
update – gets info about packages available from the installation sources

upgrade – upgrades all installed packages to the newest version available

dselect–upgrade – performs any changes in package status left undone after running dselect
apt–get cmd
dist–upgrade
install
remove
source
dist–upgrade – Similar to upgrade, but performs “smart” conflict resolution to avoid upgrading a package if doing so would break a dependency

install – install a package by package name

remove – removes a specified package by package name

source – Retrieves the newest available source package file by package filename
using information about available packages and installation archives listed in /etc/apt/sources.list.
apt–get cmd
check
clean
autoclean
check – checks the package DB for consistency and broken package installation

clean – clears out info about retrieved files from the Debian package DB

autoclean – like clean but removes info only about packages that can no longer be downloaded
apt–get options
–d
–f
–m
–d or ––download–only
used wit upgrade, dselect–upgrade, install, source
Desc: Downloads package files but doesn’t install them.

–m, ––ignore–missing, or
––fix–missing
used wit upgrade, dselect–upgrade, install, source
Desc: Ignores all package files that can't be retrieved

–f or ––fix–broken
used with install, remove
Attempts to fix a system on which dependencies are unsatisfied
apt–get options
–q
–s
–y
–q or ––quiet
used with All
Omits some progress indicator information. –qq produces still less info

–s, ––simulate, ––just–print, ––dry–run, ––recon, or ––no–act
used with All
Performs a simulation of the action without actually modifying, installing, or removing files.

–y, ––yes, or ––assume–yes
used with All
Produces a “yes” response to any yes/no prompt in installation scripts.
apt–get options
–b
––no–upgrade
–b
used with source
Compiles a source package after retrieving it.

––no–upgrade
used with install Causes apt–get to not upgrade a package if an older version is already installed.
dselect program def
a high level package browser
path to the APT archives
/etc/apt/source.list
aptitude. program def
text–based Debian package manager

aptitude cmd
install – aptitude install zsh
remove – aptitude remove zsh
full–upgrade
safe–upgrade
serach – aptitude search samba
help – aptitude help
Synaptic
tool that’s similar to dselect and aptitude in some ways is Synaptic, but Synaptic
is a fully GUI X–based program and as such is easier to use
Reconfiguring Packages
Debian packages offer more options during set up than RPM.
If you want to alter a package after it has been installed run
dpkg–reconfigure
this will re–run the installation scripts included in the package
Debian pckg vs RPM pgck
Debian:
src pckg arent a single file
must transport at least 2 file (tarball and patch)
support just one patch file
RPM:
may contain multiple patch files
What files are included in a Debian package file?
1)original source tarball
2)patch file used to modify the source code
(including a file that control building a Debian package)
3).dsc file – containing a digital "signature" to help verify authenticity
main config file for dkpg is ....
/etc/dpkg/dpkg.cfg or ~/dpkg.cfg
main config file for APT
/etc/apt/sources.list
also
/ect/apt/apt.conf – Controls the APT dselect options
ISC
BIND
ICS–internet software consortium
BIND–berkley Internet NAme Domain
alien program
comes with Debian and a few other
can install by using apt–get install alien
main functionality is to convert between packages
requires both package management software installed
alien opt
––de–deb
––to–rpm
––to–slp
––to–tgz
––to–deb – converts Debian,
––to–rpm – converts RPM,
––to–slp – converts Stampede,
––to–tgz – converts tarball format
Debian package to RPM
# alien ––to–rpm someprogram–1.2.3–4_i386.deb
Debian–based system and want to install a tarball but keep a record of the files it contains in your Debian package database
# alien ––install binary–tarball.tar.gz
Qt (expl)
all KDE programs rely on Qt, a widget set that provides assorted GUI tools. If Qt isn’t installed, you won’t be able to install any KDE packages using RPMs or Debian packages.
In rpm how to tell the program to ignore failed dependencies by
using
rpm –i apackage.rpm ––nodeps
In rpm how to tell the program to force installation over some other errors, such as conflicts with existing packages
rpm –i apackage.rpm ––force
dpkg how to ignore dependencies
dpkg how to force any conflict problems
––ignore–depends=package
––force–depends

––force–conflicts
RPM–based system, the command to rebuild a package is
# rpmbuild ––rebuild packagename–version.src.rpm

do this you must have the source RPM for the package
libc (desc)
libc is one of the most important libraries is the C library
widget sets (desc)
libraries are often called widget sets because they provide the on–screen widgets used by programs—buttons, scroll bars, menu bars, and so on.
glibc (desc)
glibc is version of the C library
n Linux, shared libraries usually have an extension of
.so or .so.version extension, where version is a version number. (.so stands for shared object.)
Linux static libraries (used by linkers for inclusion in programs when dynamic libraries aren’t to be used) have an extension
.a filename extensions
Static libraries are sometimes used by developers ...
Static libraries are sometimes used by developers who create programs using particularly odd, outdated, or otherwise exotic libraries. This enables them to distribute their binary packages without requiring users to obtain and install their oddball libraries.
to set a library path (global)
set the library path is to edit the /etc/ld.so.conf

file consists of a series of lines, each of which lists one directory in which shared library files may be found

Ubuntu 8.04’s ld.so.conf begins with this line: include /etc/ld.so.conf.d/*.conf
LD_LIBRARY_PATH environment variable
This environment variable specifies additional directories the system is to search for libraries.
Mainly use when you want to change the path not permanently/globally

$ export LD_LIBRARY_PATH=/usr/local/testlib:/opt/newlib

line adds two directories, /usr/local/testlib and /opt/newlib, to the search path.
$ gimp
gimp: error while loading shared libraries: libXinerama.so.1: cannot
open shared object file: No such file or directory

What this message indicate?
message indicates that the system couldn’t find the libXinerama.so.1 library file. The usual cause of such problems is that the library isn’t installed
creating a symbolic link will correct the problem
ln –s biglib.so.5.2 biglib.so.5

You must type this command as root in the directory in hich the library resides. You must then run ldconfig
ldd program
displays a program’s shared library dependencies—that is, the shared libraries
that a program uses.
ldconfig program
# ldconfig

updates caches and links used by the system for locating libraries—that is, it reads /etc/ld.so.conf and implements any changes in that file or in the directories to which it refers
cmd to check which libraries the program file uses
$ ldd /bin/ls

librt.so.1 => /lib/librt.so.1 (0x0000002a9566c000)
libncurses.so.5 => /lib/libncurses.so.5 (0x0000002a95784000)

If the library name doesn’t contain a complete path, ldd attempts to find the true library and displays the complete path following the => symbol, as in /lib/librt.so.1 or /lib/libncurses.so.5.
ldd cmd option –v
ldd –v
displays a long list of version information following the main entry.
# ldconfig –v
# ldconfig –N
# ldconfig –n
# ldconfig –p
# ldconfig –v – verbouse display – causes the program to summarize the directories and files it’s registering as it goes about its business

# ldconfig –N – dont rebuild cache – auses ldconfig to not perform its primary duty of updating the library cache

# ldconfig –n – process only specified dir – causes ldconfig to update the links contained in the directories specified on the command line

# ldconfig –p – display current info – causes ldconfig to display the current cache—all the library directories and the libraries they contain.
# ldconfig –X
# ldconfig –f
# ldconfig –C
# ldconfig –r
# ldconfig –X – dont update links – –X option is the opposite of –N; it causes ldconfig to update the
cache but not manage links

# ldconfig –f – use a new config file – change the configuration file from /etc/ld.so.conf by using the –f conffile option, where conffile is the file you want to use

# ldconfig –C – use a new cache file – change the cache file that ldconfig creates by passing the –C cachefile option, where cachefile is the file you want to use

# ldconfig –r – use a new root – –r dir option tells ldconfig to treat dir as if it were the root (/)
directory. This option is helpful when you’re recovering a badly corrupted system or installing
a new OS
uname command
display information about the kernel
# uname –n
# uname –s
# uname –v
# uname –n or ––nodename
displays the system's node name (netwokr host name)

# uname –s or ––kernel–na
display the kernel name, which is usually Linux

# uname –v or ––kernel–version
this holds the kernel build date and time, not an actual version number
# uname –r
# uname –m
# uname –p
# uname –r or ––kernel–release
actual kernel version number can be found

# uname –m or ––machine
returns information about your machine. This is likely to be a CPU code, such as i686 or x86_64.

# uname –p or ––processor
return information about your CPU, such as the manufacturer, model, and clock speed; in practice, it returns unknown on many systems.
# uname –i
# uname –o
# uname –a
# uname –i or ––hardware–platform
Hardware platform information, but this often returns unknown

# uname –o or ––operating–system
returns the OS name—normally GNU/Linux for a Linux system

# uname –a or ––all
returns all available information.
ps cmd
program displays processes’ status
ps [options]
ps supports three different types of options

Unix98 options – These single–character options may be grouped together and are preceded by a single dash (–).
BSD options – These single–character options may be grouped together and must not be preceded by a dash.
GNU long options – These multi–character options are never grouped together. They’re preceded by two dashes (––).
PS_PERSONALITY environment
you can change some of ps default behaviors by setting the PS_PERSONALITY environment variable to posix, old, linux, bsd, sun, digital, or various others
ps ––help

ps –A

ps –e

px x
–help option presents a summary of some of the more common ps options

–A / –e / x
By default, ps displays only processes that were run from its own terminal
–A and –e options cause it to display all the processes on the system
x displays all processes owned by the user who gives the cmd
ps –u
ps U
ps ––User
variable may be a username or a user ID

display processes owned by a given user with the –u user, U user, and ––User user options
ps –f
ps –l
ps j
ps l
ps u
The –f, –l, j, l, u, and v options all expand the information
provided in the ps output.
ps –H
ps –f
ps ––forest

ps –w or w
The –H, –f, and ––forest options group processes and use indentation to show the hierarchy of relationships between processes. These options are useful if you’re trying to trace the parentage of a process.

–w and w
ps u tell ps not to do this, which can be useful if you direct the output to a file, as in ps w > ps.txt.
ps –u rodsmith ––forest (example)
$ ps –u rodsmith ––forest
PID TTY TIME CMD
2451
ps u U rodsmith (example)
USER PID
abriviations in ps screens
PID
PPID
TTY
PID – process ID
PPID – parent process ID
TTY – teletype
code that identify the terminal.
Not all processes have TTY – X programs and daemons dont
abriviations in ps screens
CPU time

CPU priority

NI
CPU time
TIME and %CPU headings are two measures of CPU time used. The first indicates the total amount of CPU time consumed, and the second represents the percentage of CPU time the process is using when ps executes

CPU priority
it’s possible to give different processes different priorities for CPU time

NI
lists these priority codes. The default value is 0. Positive values represent reduced priority, whereas negative values represent increased priority
abriviations in ps screens
RSS

%MEM

SHARE
RRS – resident set size
memory used by the program and its data

%MEM
the percentage of memory the program is using

SHARE
memory that's shared with other processes such as library
It’s often necessary to find specific processes. You might want to find the PID associated with a particular command in order to kill it, for instance. This information can be gleaned by piping the ps output through grep, as in
ps ax | grep bash to find all the instances of bash.
top cmd

what are kpm and gnome–system–monitor?
top: A Dynamic ps Variant

GUI variants of top
top options
–d
–p
–n
–b
–d delay
specifies the delay between updates

–p pid
to monitor specific process, can specify up to for PID

–n iter
top displays certain number of updates (iterations) and stops

–b
batch mode, top doesn't use the normal screen–update cmds
top when running cmds
h and ?

k

q
h and ?
help info

k
kill a process, top will ask for PID

q
quits top
top when running cmds
r

s

P

M
r
changes priority with this cmd, asks for PID number

s
displays update rate

P
sort by CPU usages

M
sort by memory usage
load average
One of the pieces of information provided by top is the load average, which is a measure of the demand for CPU time by applications.
A system on which no programs are demanding CPU time has a load average of 0. A system with one program running CPU–intensive tasks has a load average of 1. Higher load averages reflect programs competing for available CPU time.
uptime command
displays the load average along with information on how long the computer has been running
jobs command
displays minimal information about the processes associated with the current session.
second use of job is to determine if all apps are closed prior to us logging out
If a program is running but you decide you want to use that terminal for something else, pressing ____ normally pauses the program and gives you control of the terminal.
Ctrl+Z

running a text editor in a textmode
login, and you want to check a filename so you can mention it in the file you’re editing.
You press Ctrl+Z and type ls to get the file listing. To get back to the text editor, you
then type fg, which restores the text editor to the foreground of your terminal, if you have suspended more than 1 process use fg 2
fg cmd

bg cmd
restores a job to the foreground

bg restores a job to running status, but in the background
run a program in the background (third way)
you can append an ampersand (&) to the command when launching the program.

rather than edit a file with the NEdit GUI editor by typing nedit myfile.txt, you can type nedit myfile.txt &
nice cmd
nice [argument] [command [command–arguments]]

You can assign a priority to nice in any of three ways:
1)by specifying the priority preceded by a dash
2)by specifying the priority after a –n parameter
3)by specifying the priority after an ––adjustment= parameter
In all cases there parameters are followed by the name of the program

$ nice –12 number–crunch data.txt
$ nice –n 12 number–crunch data.txt
$ nice ––adjustment=12 number–crunch data.txt
renice cmd
If you’ve found that a running process is consuming too much CPU time or is being swamped by other programs and so should be given more CPU time, you can use the renice program to alter its priority without disrupting the program’s operation

renice priority [[–p] pids] [[–g] pgrps] [[–u] users]
kill command
to terminate a process that should not be running use
kill

kill –s signal pid
kill –s signal parameter
You can specify the signal using either a number (such as 9) or a name (such as SIGKILL).
Signals you’re most likely to use
1 or SIGHUP – terminates interactive prog. and causes many daemons to reread their config
9 or SIGKILL – causes the process to exit without performing routine shutdown tasks
15 or SIGTERM (default) – causes process to exit but allows it ot close open files
nohup cmd
If you want to run a program that will continue running even when you log out, you can launch it with the nohup program:

$ nohup program options

This command causes the program to ignore the SIGHUP signal
Which of the following is not an advantage of a source package over a binary package?
A. A single source package can be used on multiple CPU architectures.
B. By recompiling a source package, you can sometimes work around library incompatibilities.
C. You can modify the code in a source package, altering the behavior of a program.
D. Source packages can be installed more quickly than binary packages can.
D. Because they must be compiled prior to installation, source packages require more time to install than binary packages do, contrary to option D’s assertion.

The other options all describe advantages of source packages over binary packages.
Which is true of using both RPM and Debian package management systems on one computer?
A. It’s generally inadvisable because the two systems don’t share installed–file database information.
B. It’s impossible because their installed–file databases conflict with one another.
C. It causes no problems if you install important libraries once in each format.
D. It’s a common practice on Red Hat and Debian systems.
A. Package management systems don’t share information, but neither do their databases actively conflict. Installing the same libraries using both systems would almost guarantee that the files served by both systems would conflict with one another. Actively using both RPM and Debian packages isn’t common on any distribution, although it’s possible with all of them
Which of the following statements is true about binary RPM packages that are built for a particular distribution?
A. They can often be used on another RPM–based distribution for the same CPU architecture, but this isn’t guaranteed.
B. They may be used in another RPM–based distribution only when you set the
––convert–distrib parameter to rpm.
C. They may be used in another RPM–based distribution only after you convert the package with alien.
D. They can be recompiled for an RPM–based distribution running on another type of CPU.
A. RPMs are usually portable across distributions, but occasionally they contain incompatibilities.
There is no ––convert–distrib parameter to rpm, nor is alien used to convert
from RPM format to RPM format. Binary packages can’t be rebuilt for another CPU architecture, but source packages may be rebuilt for any supported architecture provided the source code doesn’t rely on any CPU–specific features.
An administrator types the following command on an RPM–based Linux distribution:
# rpm –ivh megaprog.rpm
What is the effect of this command?
A. The megaprog package, if it’s installed, is uninstalled from the computer.
B. The megaprog.rpm package, if it exists, is valid, and isn’t already installed, is installed on the system.
C. The megaprog.rpm source RPM package is compiled into a binary RPM for the computer.
D. Nothing; megaprog.rpm isn’t a valid RPM filename, so rpm will refuse to operate on this file.
B. The –i operation installs software, so option B is correct. (The –v and –h options cause
a status display of the progress of the operation, which wasn’t mentioned in the option.)
Uninstallation is performed by the –e operation, and rebuilding source RPMs is done by the ––rebuild operation (to either rpm or rpmbuild, depending on the RPM version). Although the filename megaprog.rpm is missing several conventional RPM filename components, the rpm utility doesn’t use the filename as a package validity check, so option D is incorrect.
Which of the following commands will extract the contents of the myfonts.rpm file into the current directory?
A. rpm2cpio myfonts.rpm | cpio –i ––make–directories
B. rpm2cpio myfonts.rpm > make–directories
C. rpm –e myfonts.rpm
D. alien ––to–extract myfonts.rpm
A. The rpm2cpio program extracts data from an RPM file and converts it into a cpio archive that’s sent to standard output. Piping the results through cpio and using the –i and ––make–directories options, as in option A, will extract those files to the current directory.

Option B creates a cpio file called make–directories that contains the files from the RPM package.
Option C will uninstall the package called myfonts.rpm (but not the myfonts package).
The alien utility has no ––to–extract target, so option D is invalid.
To use dpkg to remove a package called theprogram, including its configuration files, which of the following commands would you issue?
A. dpkg –P theprogram
B. dpkg –p theprogram
C. dpkg –r theprogram
D. dpkg –r theprogram–1.2.3–4.deb
A. An uppercase –P invokes the purge operation, which completely removes a package and its configuration files. The lowercase –p causes dpkg to print information about the package’s contents. The –r parameter removes a package but leaves configuration files behind.
The final variant (option D) also specifies a complete filename, which isn’t used for removing a package—you should specify only the shorter package name
Which of the following describes a difference between apt–get and dpkg?

A. apt–get provides a GUI interface to Debian package management; dpkg doesn’t.
B. apt–get can install tarballs in addition to Debian packages; dpkg can’t.
C. apt–get can automatically retrieve and update programs from Internet sites; dpkg can’t.
D. apt–get is provided only with the original Debian distribution, but dpkg comes with Debian and its derivatives.
C. You can specify Debian package archive sites in /etc/apt/sources.list, and then you can type apt–get update and apt–get upgrade to quickly update a Debian system to the latest packages. GUI package management tools for Debian and related distributions exist, but they aren’t apt–get. The alien program can convert an RPM file and install the converted package on a Debian system; dpkg and apt–get both come with all Debian–based distributions.
What command would you type to obtain a list of all installed packages on a Debian system?
A. apt–cache pkgnames
B. apt–cache showpkg
C. dpkg –r allpkgs
D. dpkg –i
A. The apt–cache subcommand pkgnames displays the names of all installed packages
or, if a further string is used, of all installed packages whose names begin with that string,
making option A correct.

The showpkg subcommand to apt–cache displays information about a named package; when used without a package name, as in option B, it displays no data.
The dpkg –r action removes a package, so option C would remove the package called allpkgs if it were installed.
The dpkg –i action installs a package, so option D is incorrect—and that option doesn’t list a package name, which the –i action requires
As root, you type apt–get update on a Debian system. What should be the effect of this command?

A. None; update is an invalid option to apt–get.
B. The APT utilities deliver information about the latest updates you’ve made to the APT Internet repositories, enabling you to share your changes with others.
C. The APT utilities download all available upgrades for your installed programs and install them on your system.
D. The APT utilities retrieve information about the latest packages available so that you may install them with subsequent apt–get commands.
D. The update option to apt–get causes retrieval of new information, as described in
option D.

This option is perfectly valid, contrary to option A’s assertion.
The apt–get program doesn’t permit you to upload information to the Internet repositories, so option B is incorrect.
Option C describes the effect of the upgrade or dist–upgrade options, not the update option.
Which of the following commands would you type to update the unzip program on a Fedora system to the latest version? (Select all that apply.)
A. yum update unzip
B. yum upgrade unzip
C. yum –u unzip
D. yum –U unzip
A, B. The yum utility’s update and upgrade options are nearly identical in effect, and either
can be used to upgrade an individual package, such as unzip. The primary command
options to yum don’t use dashes, so –u and –U are both incorrect.
How should you configure a system that uses Yum to access an additional Yum software repository?

A. Edit the /etc/apt/sources.list file to include the repository site’s URL, as detailed on the repository’s Web site.
B. Download a package from the repository site and install it with RPM, or place a configuration file from the repository site in the /etc/yum.repos.d directory.
C. Use the add–repository subcommand to yum or the Add Repository option in the File menu in yumex, passing it the URL of the repository.
D. Edit the /etc/yum.conf file, locate the [repos] section, and add the URL to the repository after the existing repository URLs.
B. Yum uses files in the /etc/yum.repos.d directory to locate its repositories, so you can add to the repository list by adding files to this subdirectory, as option B specifies, typically either by installing an RPM or by adding a file manually.

Option A describes a method of adding a repository to a computer that uses APT, not Yum.
Option C’s add–repository subcommand is fictitious.
Although the /etc/yum.conf file described in option D is real, it doesn’t store repository data.
What is the preferred method of adding a directory to the library path for all users?

A. Modify the LD_LIBRARY_PATH environment variable in a global shell script.
B. Add the directory to the /etc/ld.so.conf file, and then type ldconfig.
C. Type ldconfig /new/dir, where /new/dir is the directory you want to add.
D. Create a symbolic link from that directory to one that’s already on the library path.
B. The /etc/ld.so.conf file holds the global library path, so editing it is the preferred approach. You must then type ldconfig to have the system update its library path cache.

Option A – Although you can add a directory to the library path by altering the LD_LIBRARY_PATH environment variable globally, this approach isn’t the preferred one.
Option C simply won’t work.
Option D also won’t work, although linking individual library files would work. This method isn’t the preferred one for adding a whole directory, though.
You prefer the look of GTK+ widgets to Qt widgets, so you want to substitute the GTK+ libraries for the Qt libraries on your system. How would you do this?

A. You must type ldconfig ––makesubs=qt,gtk. This command substitutes the GTK+ libraries for the Qt libraries at load time.
B. You must uninstall the Qt library packages and re–install the GTK+ packages with the ––substitute=qt option to rpm or the ––replace=qt option to dpkg.
C. You must note the filenames of the Qt libraries, uninstall the packages, and create symbolic links from the Qt libraries to the GTK+ libraries.
D. You can’t easily do this; libraries can’t be arbitrarily exchanged for one another. You would need to rewrite all the Qt–using programs to use GTK+.
D. Libraries are selected by programmers, not by users or system administrators. If you don’t like the widgets provided by one library, you have few options. (Many widget sets do provide a great deal of configurability, though, so you may be able to work around the problem in other ways.)

Options A and B describe fictitious options to ldconfig, rpm, and dpkg.
Option C wouldn’t work; Qt–using programs would crash when they found GTK+ libraries in place of the Qt libraries they were expecting.
A user types kill –9 11287 at a bash prompt. What is the probable intent, assuming the user typed the correct command?

A. To cut off a network connection using TCP port 11287
B. To display the number of processes that have been killed with signal 11287 in the last nine days
C. To cause a server with process ID 11287 to reload its configuration file
D. To terminate a misbehaving or hung program with process ID 11287
D. The kill program accepts various signals in numeric or named form (9 in this example) along with a process ID number (11287 in this example). Signal 9 corresponds to SIGKILL, which is an extreme way to kill processes that have run out of control. Although you might use kill to kill network processes, you can’t pass kill a TCP port number and expect it to work. The program also won’t display information about the number of processes that have
been killed. To do as option C suggests, you’d need to tell kill to pass SIGHUP (signal 1), so the command would be kill –1 11287.
What programs might you use to learn what your system’s load average is? (Select all that apply.)
A. ld
B. load
C. top
D. uptime
C, D. The top utility displays a dynamic list of processes ordered according to their CPU use along with additional system information, including load averages. If you want only the load average at a specific moment, uptime may be better because it presents less extraneous information—it shows the current time, the time since the system was booted, the number of active users, and the load averages. The ld command has nothing to do with displaying load averages (it’s a programming tool that links together program modules into an executable program). There is no standard Linux program called load.
Which of the following commands creates a display of processes, showing the parent/child relationships through links between their names?

A. ps ––forest
B. ps aux
C. ps –e
D. All of the above
A. The ––forest option to ps shows parent/child relationships by creating visual links between process names in the ps output. (Listing 2.4 shows this effect.)
Options B and C are both valid ps commands, but neither creates the specified effect.
You use top to examine the CPU time being consumed by various processes on your system. You discover that one process, dfcomp, is consuming more than 90 percent of your system’s CPU time. What can you conclude?

A. Very little; dfcomp could be legitimately consuming that much CPU time or it could be an unauthorized or malfunctioning program.
B. No program should consume 90 percent of available CPU time; dfcomp is clearly malfunctioning and should be terminated.
C. This is normal; dfcomp is the kernel’s main scheduling process, and it consumes any unused CPU time.
D. This behavior is normal if your CPU is less powerful than a 2.5GHz EM64T Pentium; but on newer systems, no program should consume 90 percent of CPU time.
A. CPU–intensive programs routinely consume 90 percent or more of available CPU time, but not all systems run such programs. Furthermore, some types of program bugs can create such CPU loads. Thus, you must investigate the matter more. What is dfcomp? Is it designed as a CPU–intensive program? Is it consuming this much CPU time consistently, or was this a brief burst of activity?
You type jobs at a bash command prompt and receive a new command prompt with no intervening output. What can you conclude?

A. The total CPU time used by your processes is negligible (below 0.1).
B. No processes are running under your username except the shell you’re using.
C. The jobs shell is installed and working correctly on the system.
D. No background processes are running that were launched from the shell you’re using.
D. The jobs command summarizes processes that were launched from your current shell. When no such processes are running, jobs returns nothing, so option D is correct.

The jobs command doesn’t check or summarize CPU load, so option A is incorrect.
The jobs command also doesn’t check for processes run from shells other than the current one, so option B is incorrect (processes running under your username could have been launchedfrom another shell or from a GUI environment).
There is no standard jobs shell in Linux, so option C is incorrect.
Which two of the following commands are equivalent to one another? (Select two.)
A. nice ––value 10 crunch
B. nice –n –10 crunch
C. nice –10 crunch
D. nice crunch
C, D. The nice command launches a program (crunch in this example) with increased or decreased priority. The default priority when none is specified is 10, and the nice –10 crunch command also sets the priority to 10, so options C and D are equivalent.

Option A isn’t a valid nice command because nice has no ––value option.
Option B is a valid nice command, but it sets the priority to –10 rather than 10.
Which of the following are restrictions on ordinary users’ abilities to run renice? (Select all that apply.)

A. Users may not modify the priorities of processes that are already running.
B. Users may not modify the priorities of other users’ processes.
C. Users may not decrease the priority (that is, increase the priority value) of their own processes.
D. Users may not increase the priority (that is, decrease the priority value) of their own processes.
B, D. Linux insulates users’ actions from one another, and this rule applies to renice; only root may modify the priority of other users’ processes. Similarly, only root may increase the priority of a process, in order to prevent users from setting their processes to maximum priority, thus stealing CPU time from others.

Option A correctly describes nice, but not renice; the whole point of renice is to be able to change the priorities of existing processes.
Option C also describes an action that renice permits.
Cmd to display shared libraries required by each of the programs listed on the command line.
The result indicate the name of the library and where the library is expected to be in the filesystem
ldd

bash shell requires three shared libraries

#ldd /bin/bash
/bin/bash:
libtermcap.so.2 => /lib/libtermcap.so.2
libc.so.6 => /lib/libc.so.6
/lib/ld–linux.so.2 => /lib/ld–linux.so.2
bash (descr.)

bsh (descr.)
bash (descr.)
Bourne Again Shell
base on earlier Bourne shell but extended
The most commong default shell

bsh (descr.)
Bourne shell
bsh is base for bash
not often used in linux
tcsh (descr.)

csh (descr.)
tcsh (descr.)
based on C shell (csh)
no major Linux distro use it

csh (descr.)
original C shell
not used on Linux
ksh (descr.)

zsh (descr.)
ksh
The Korn shell
Combines Bourne shell and C shell

zsh
The Z shell
incorporates features from earlier shells and adding still more
What is the file /bin/sh
is a symbolic link to the system's default shell
normaly this is /bin/bash for Linux
for the most part, Linux cmd are ____________________
a few commands are _______ to the shell
for the most part, Linux cmd are EXTERNAL – separate programs from the shell. A few commands are INTERNAL to the shell
change the working directory
cd
cd /home/sally
what ~ stands for
~ is a shortcut it stands for your home directory
cd ~
will have the same effect as
cd /home/sally
display a line of text cmd
execute a program cmd
echo Hello
exec myprog
in most cases executing a program is better done by typing the name of the program
"time" cmd
time cmd
times how long subsequent cmd takes t oexecutre
time pwd – tells you how long the system took to execute
Three times are displayed: total executin time
user CPU time
system CPU time
"set" cmd
set
in its most basic form set displays a wide variety of options relating to bash
PATH enviorment varialbe
When you type a cmd that is not recognized by the sjell as one of its internal cmds, the shell checks its path to fina a program by that name to execute it.
Define by the PATH enviroment variable.
You can adjust by changing the PATH enviorment
Warning for PATH
root’s path should never include the current directory
./.
Placing this directory in root’s path makes it possible for a local miscreant
to trick root into running replacements for common programs, such
as ls, by having root change into a directory with such a program. Indeed,
omitting the current directory from ordinary user paths is also generally a
good idea. If this directory must be part of the ordinary user path, it should
appear at the end of the path so that the standard programs take precedence
over any replacement programs in the current directory
command completion
Type part of a command
or (as an option to a command) a filename, and then press the Tab key. The shell tries to fill
in the rest of the command or the filename.
history
Another helpful shell shortcut is the history. The history keeps a record of every command you type (stored in ~/.bash_history in the case of bash).
open termina in Ubuntu
Ctrl + Alt + T

Dash –> More Apps –> 'See More Results' –> Terminal

Dash –> More Apps –> Accessories –> Terminal
xterm (cmd)
will launch the xterm shell
touch

clear (cmd)
create a brand new blank file

clears terminal window
shutdown linux cmd
and
how to reboot?
sudo shutdown –h now
sudo shutdown –h 0
sudo shutdown –h 18:45 "Server is going down for maintenance"

Please note that you can also use halt or poweroff or reboot command for stopping and restarting the system:
$ sudo halt
$ sudo poweroff
How do I reboot computer?
sudo shutdown –r 0
sudo reboot
using command history
CTRL + R – backward search
CTRL + S – forward search
CTRL + G – terminates search
move within the command line
CTRL + A/CTRL + E
moves cursor to the start or end of the line
<– and –> move the cursor a character at a time same as (CTRL+B and CTRL+F)
CTRL+K – del. all text from current cursor to the end of line
invoka an editor
lanch full editor by pressing
CTRL + X followed by CTRL + E
Bash shell attempts to launch the editor defined by the $FCEDIT or $EDITOR
delete a file
rm –f –r {file–name}

■–f: Forcefully remove file
■–r: Remove the contents of directories recursively
main user config file for bash

main global config file for bash
main user config file for bash
~/.bashrc
~/.profile
main global config file for
bash
/etc/bash.bashrc
/etc/profile
cmd to learn about man itself
man man
for instance, passwd has entries
under both section 1 and section 5. In most cases, man returns the entry in the lowest–numbered
section; but you can force the issue by preceding the keyword by the section number.What cmd does that
man 5 passwd
Some programs have moved away from man pages to info pages. The basic purpose of
info pages is the same as that for man pages, but info pages use a hypertext format
info info
Redirecting Input and Output
echo $NNTPSERVER > nntpserver.txt
What creates a new file containing standard output. If the specified file
exists, it’s overwritten.
>
Appends standard output to the existing file. If the specified file
doesn’t exist, it’s created.
>>
Creates a new file containing standard error. If the specified file
exists, it’s overwritten.
2>
Appends standard error to the existing file. If the specified file
doesn’t exist, it’s created.
2>>
Creates a new file containing both standard output and standard
error. If the specified file exists, it’s overwritten.
&>
Sends the contents of the specified file to be used as standard
input.
Accepts text on the following lines as standard input.
<
Causes the specified file to be used for both standard input and
standard output.
<>
what is /dev/null
This file is a device that’s connected to nothing; it’s used when you
want to get rid of data.
For instance, if the whine program is generating too
many error messages, you can type whine 2> /dev/null to run it and discard
its error messages.
tee command
his command splits standard input so that
it’s displayed on standard output and on as many files as you specify.

someprog | tee output.txt
data pipes (a.k.a. pipelines)
A pipe redirects the first program’s
standard output to the second program’s standard input and is denoted by a vertical bar (|):
$ first | second
general rule for files ending with ~
file ending with ~ denote backups files created by certain text editors
xargs [options] [command [initial–arguments]]

general usage
xargs cmd builds a comand from its standard input.

command – the cmd you want to executre
initial–arguments – list of argumentsyou want to pass to the cmd
options – xargs options
using xargs delete all file that end with ~
$ find ./ –name “*~” | xargs rm
The first part of this command (find ./ –name “*~”) finds all the files in the current
directory (./) or its subdirectories with a name that ends in a tilde (*~). This list is then
piped to xargs, which adds each one to its own rm command.
what is backtick (`)
Text within backticks is treated as a separate command whose results are substituted on the
command line.
$ rm `find ./ –name “*~”`
mac categories
1 Executable programs and shell commands
2 System calls provided by the kernel
3 Library calls provided by program libraries
4 Device files (usually stored in /dev)
5 File formats
6 Games
7 Miscellaneous (macro packages, conventions, and so on)
8 System administration commands (programs run mostly or exclusively
by root)
9 Kernel routines
uses for ` (backtick)
the text within backticks is treated as a separete cmd whose results are substituted on the cmd line

rm `fin ./ –name "*~"` – deletes all files ending with ~
cat (cmd)
links together an arbitrary number of files end to end and send the result to standard output

cat first.txt second.txt > combined.txt
Display line ends cmd

Number lines cmd
cat –E or
cat ––show–ends
The result is dollar sign at the end of each file

cat –n
cat ––number
Adds line numbers to the beginning of every line even empty
Number lines but not blank
cat –b
car ––number–nonblank
adds a line numbers but it numbers only lines that contain text
cmd option that compresses groups of blank lines down to a single blank line
cat –s
cat ––squeeze–blank
cmd option to display special character

cmd option that display most control and other special characters using carat (^) and M– notations
cat .. –T
cat .. ––show–tabs

cat .. –v
cat .. show–tabs
join cmd (expl)
join command combines two files by matching the contents of specified fields within
the files. Fields are typically space–separated entries on a line, although you can specify
another character as the field separator with the –t char option, where char is the character
you want to use. You can cause join to ignore case when performing comparisons by
using the –i option.
join cmd example
ls1.txt
555–2397 Beckett, Barry
555–5116 Carter, Gertrude
ls2.txt
555–2397 unlisted
555–5116 listed

$ join listing1.1.txt listing1.2.txt
555–2397 Beckett, Barry unlisted
555–5116 Carter, Gertrude listed
paste cmd example
ls1.txt
555–2397 Beckett, Barry
555–5116 Carter, Gertrude
ls2.txt
555–2397 unlisted
555–5116 listed

$ paste listing1.1.txt listing1.2.txt
555–2397 Beckett, Barry 555–2397 unlisted
555–5116 Carter, Gertrude 555–5116 listed
paste (cmd)
paste command merges files line by line, separating the lines from each file with tabs

paste listing1.1.txt listing1.2.txt
Converting Tabs to Spaces (cmd)
expand

By default, expand assumes a tab stop every eight characters. You can change this spacing
with the –t num or ––tabs=num option, where num is the tab spacing value.
Displaying Files in Octal (cmd)
od – octal dump

Displaying Files in Octal

od listing1.2.txt
0000000 032465 026465 031462 033471 072440 066156 071551 062564
Sorting Files (cmd)
sort

–f or ––ignore–case
–M or ––month–sort – sort by three–letter month abbr
–n or ––numeric–sort
–k field or ––key=field option. (The field can be two numbered fields separated by commas, to sort on multiple fields.)
$ sort –k 3 listing1.1.txt
Breaking a File into Pieces (cmd)
split

Split by bytes –b size or ––bytes=size This option can have the usually undesirable consequence of splitting the file mid–line.
Split by bytes in line–sized chunks –C=size or ––line–bytes=size option.
Split by number of lines The –l lines or ––lines=lines
Translating Characters (cmd)
tr
You specify the characters you want replaced in a group (SET1) and the characters with
which you want them to be replaced as a second group (SET2). Each character in SET1 is
replaced with the one at the equivalent position in SET2
$ tr BCJ bc < listing1.1.txt
Converting Spaces to Tabs (cmd)
unexpand command is the logical opposite of expand; it converts multiple spaces to
tabs.
Deleting Duplicate Lines (cmd)
uniq

$ sort shakespeare.txt | uniq
Reformatting Paragraphs
fmt
If you want to clean up the file a bit, though, you can do so with fmt. If called with no options the program attempts to clean up paragraphs, which it assumes are delimited by two or more blank lines or by changes in indentation
Numbering Lines
Body numbering
Header and Footer numbering
nl
Body numbering style –b style or ––body–numbering=style
Header and footer numbering style
–h style or ––header–numbering=style
–f style or ––footer–numbering=style
Numbering Lines Number format (cmd)
Page separator – Some numbering schemes reset the line numbers for each page
Line–number options for new pages –p or ––no–renumber
Number format –n format or ––numberformat=
format option, where format is ln (left justified, no leading zeros), rn (right justified,
no leading zeros), or rz (right justified with leading zeros)
Numbering Lines Number only non–blank lines (cmd)
The default behavior is to number lines that aren’t empty.
This corresponds to a style of t.
Numbering Lines Number all lines, Number no lines (cmd)
Number all lines
specify a style of a
Number no lines
specify a style of n
Numbering Lines Number lines matching a regular expression (cmd)
A style of pREGEXP numbers only those
lines that match the regular expression REGEXP.
suppose you’ve created a script, buggy, but you find that it’s not working
as you expect. When you run it, you get error messages that refer to line numbers, so you
want to create a version of the script with lines that are numbered for easy reference. What cmd you use?
$ nl –b a buggy > numbered–buggy.txt
Preparing a File for Printing (cmd)
pr

If you want to print a plain–text file, you may want to prepare it with headers, footers, page
breaks, and so on. The pr command was designed to do this. In its most basic form, you
pass the command a file:
$ pr myfile.txt
pr Generate multi–column output (cmd option)
Passing the –numcols or ––columns=numcols option creates
output with numcols columns. Note that pr doesn’t reformat text; if lines are too long,
they’re truncated or run over onto multiple columns.
pr Generate double–spaced output (cmd option)
–d or ––double–space option causes double–spaced
output from a single–spaced file.
pr Use form feeds (cmd option)
pr separates pages by using a fixed number of blank lines If you have
problems with this issue, you can pass the –F, –f, or ––form–feed option, which causes pr
to output a form–feed character between pages.
pr Set page length (cmd option)
+ Set the header text
+ Set left margin and page width
The –l lines or ––length=lines option sets the length of the page in lines.
The –h text or ––header=text
The –o chars or ––indent=chars option sets the left margin
to chars characters
example of pr in action, consider printing a double–spaced and numbered version
of a configuration file (say, /etc/profile) for your reference
cat –n /etc/profile | pr –d | lpr
Viewing the Starts of Files
head
Specify the number of bytes The –c num or ––bytes=num option tells head to display num
bytes from the file rather than the default 10 lines.
Specify the number of lines You can change the number of lines displayed with the –n
num or ––lines=num option.
Viewing the Ends of Files
tail

–c/––bytes and –n/––lines options to change the amount of data displayed,
just as with head
tail Track a file (option)
!!!
–f or ––follow option tells tail to keep the file open and to display new
lines as they’re added. This feature is helpful for tracking log files because it enables you to
see changes as they’re added to the file.
tail Stop tracking on program termination (option)
––pid=pid option tells tail to terminate
tracking (as initiated by –f or ––follow) once the process with a process ID (PID) of pid
terminates
Paging Through Files (option)
less – less filename
less usage options
Pressing the spacebar moves forward through t NN he file a screen at a time.
NN Pressing Esc followed by V moves backward through the file a screen at a time.
NN The Up and Down arrow keys move up or down through the file a line at a time.
NN You can search the file’s contents by pressing the slash (/) key followed by the search
term. For instance, typing /portable
You can search backward in the file by using the question mark (?) key rather than the
slash key.
NN You can move to a specific line by typing g followed by the line number, as in g50 to go
to line 50.
q to exit the program
Extracting Text (cmd)
cut command extracts portions of input lines and displays them on standard output
cut by byte
cut by character
cut by fiels
By byte The –b list or ––bytes=list
By character The –c list or ––characters=list The –f list or ––fields=list option cuts the specified list of fields from the input
file.
extract the mac address from ifconfig using grep and cut
$ ifconfig eth0 | grep HWaddr | cut –d “ “ –f 11
Obtaining a Word Count
wc file.txt
308 2343 15534 file.txt
limit the output
––lines (–l), ––words (–w), ––bytes (–c), or ––chars (–m)
command that searches for files that contain a specified string and returns the name of the file and (if it’s a text file) a line of context for that string
grep [options] regexp [files]
grep Count matching lines

grep Specify a pattern input file
Count matching lines Instead of displaying context lines, grep displays the number of
lines that match the specified pattern if you use the –c or ––count option.

Specify a pattern input file The –f file or ––file=file option takes pattern input from
the specified file rather than from the command line.
grep Ignore case

grep Search recursively
Ignore case You can perform a case–insensitive search, rather than the default case–sensitive
search, by using the –i or ––ignore–case option.

Search recursively The –r or ––recursive option searches in the specified directory and
all subdirectories rather than simply the specified directory. You can use rgrep rather than
specify this option.
grep Use an extended regular expression
Use an extended regular expression The grep command interprets regexp as a basic regular
expression by default. To use an extended regular expression, you can pass the –E or
––extended–regexp option. Alternatively, you can call egrep rather than grep; this variant
command uses extended regular expressions by default.
finds all the files in /etc that contain the string eth0
$ grep –r eth0 /etc/*

–r option, it searches recursively, so files in subdirectories of /etc are examined as well as those in /etc itself.
you want to locate all the files in /etc that contain the string
eth0 or eth1
$ grep eth[01] /etc/*
searches all files in /etc that contain the hostname twain.
example.com or bronto.pangaea.edu and, later on the same line, the number 127. This task
requires using several of the regular expression features.
$ grep –E “(twain\.example\.com|bronto\.pangaea\.edu).*127” /etc/*
shell quoting
Because
the shell uses certain characters, such as the vertical bar and the asterisk, for its own purposes,
you must enclose certain regular expressions in quotes lest the shell attempt to parse
the regular expression as shell commands.

$ grep –E “(twain\.example\.com|bronto\.pangaea\.edu).*127” /etc/*
you want to find the process
ID (PID) of a running xterm
You can use a pipe to send the result of a ps command through grep
# ps ax | grep xterm
sed (cmd)
sed command directly modifies the contents of files, sending the changed file to standard
output. Its syntax can take one of two forms:
sed [options] –f script–file [input–file]
sed [options] script–text [input–file]
sed cmd addresses explanation
sed commands operate on
addresses, which are line numbers. Commands may take no addresses, in which case they operate on the entire file; one address, in which case they operate on the specified line; or two addresses (a range), in which case they operate on that range of lines, inclusive
sed cmd Append text to the file.

sed cmd Append text to the file.

sed cmd Append text to the file
a\text – 0|1 – Append text to the file

i\text – 0|1 – Insert text into the file

r filename – 0|1 – Append text from filename into the file
sed cmd Replace the selected range of lines with the
provided text

sed Replace text that matches the regular expression
(regexp) with replacement.
c\text – Range – Replace the selected range of lines with the
provided text.

s/regexp/replacement – Range – Replace text that matches the regular expression
(regexp) with replacement.
sed write the current pattern space to the specified file

sed immediately quit the script, but print the current pattern space

sed immdeiately quit the scropt
w filename – Range – Write the current pattern space to the
specified file
q – 0|1 – Immediately quit the script, but print the current
pattern space
Q – 0|1 – Immediately quit the script
command processes the input file, cal–2008.txt, using sed’s s command to replace
the first occurrence of 2008 on each line with 2009.
$ sed ‘s/2008/2009/‘ cal–2008.txt > cal–2009.txt

By default, sed sends the modified file to standard output,
so this example uses redirection to send the output to cal–2009.txt. The idea in this
example is to quickly convert a file created for the year 2008 so that it can be used in 2009.