LPI Linux Certification in a Nutshell (34 page)

Read LPI Linux Certification in a Nutshell Online

Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger

Tags: #Reference:Computers

BOOK: LPI Linux Certification in a Nutshell
5.19Mb size Format: txt, pdf, ePub
Linux annex

Since FHS migrated away from being a Linux-only document and
expanded to cover other operating systems, information specific to any
one operating system was moved to an
annex
. The only annex listed in
v2.3 of FHS is the Linux annex, which mentions a few guidelines and
makes allowances for the placement of additional program files in
/sbin
. The Linux annex also mentions and supports
the use of the
/proc
filesystem for the
processing of kernel, memory, and process information.

Where’s that binary?

Compiled executable files, called
binary files
, or just
binaries
, can be located in a number of places in
an FHS-compliant filesystem. However, it’s easy to become a little
confused over why a particular executable file is placed where it is
in the FHS. This is particularly true for
bin
and
sbin
directories, which appear in multiple
locations.
Table 7-7
lists these
directories and shows how each is used.

Table 7-7. Binary file locations

Type of file

User commands

System administration
commands

Vendor-supplied, essential (root
filesystem)

/bin

/sbin

Vendor-supplied, nonessential
(
/usr
filesystem)

/usr/bin

/usr/sbin

Locally supplied, nonessential
(
/usr
filesystem)

/usr/local/bin

/usr/local/sbin

Locating Files

FHS offers the Linux community an excellent resource that
assures consistency across distributions and other operating systems. In
practice, however, file location problems can be frustrating, and the
need arises to find files in the system quickly. These file location
tools are required for Exam 101:
which, find, locate,
whereis
, and
type
.

which
uses the
PATH
variable to locate executable files.
find
searches specified areas in the filesystem.
whereis
searches in a small subset of common
directories.
locate
offers a quick alternative to
find
for filename searches and is suited for
locating files that are not moved around in the filesystem. Without a
fresh database to search,
locate
is not suitable
for files recently created or renamed.

Name

which

Syntax
which
command
Description

Determine the location of
command
and display the full pathname of
the executable program that the shell would launch to execute it.
which
searches only the user’s path.

Example

Determine the shell that would be started by entering the
tcsh
command:

#
which tcsh
/bin/tcsh

which
is small and does only one thing:
determines what executable program will be found and called by the
shell. Such a search is particularly useful if you’re having trouble
with the setup of your
PATH
environment variable or if you are creating a new version of an
existing utility and want to be certain you’re executing the
experimental version.

Name

find

Syntax
find
paths expression
Description

Locate files that match an
expression
starting at
paths
and continuing recursively. The
find
command has a rich set of
expression
directives for locating just
about anything in the
filesystem
.

Example

To find files by name located in the
/usr
directory hierarchy that might have something to do with the
csh
shell or its variants, you might use the
-name
filename
directive:

#
find /usr -name "*csh*"
/usr/bin/sun-message.csh
/usr/doc/tcsh-6.08.00
/usr/doc/tcsh-6.08.00/complete.tcsh
/usr/doc/vim-common-5.3/syntax/csh.vim
/usr/man/man1/tcsh.1
/usr/share/apps/ktop/pics/csh.xpm
/usr/share/apps/ktop/pics/tcsh.xpm
/usr/share/emacs/20.3/etc/emacs.csh
/usr/share/vim/syntax/csh.vim
/usr/src/linux-2.2.5/fs/lockd/svcshare.c

Some of these results are clearly related to
csh
or to
tcsh
, whereas
others are questionable. In addition, this command may take a while
because
find
must traverse the
entire
/usr
hierarchy, examining each filename
for a match. This example demonstrates that if filename wildcards
are used, the entire string must be quoted to prevent expansion by
the shell prior to launching
find
.

find
is among the most useful commands in
the Linux administrator’s toolkit and has a variety of useful
options.
find
is handy in certain cases. For
example:

  • You need to limit a search to a particular location in the
    filesystem.

  • You must search for an attribute other than the
    filename.

  • Files you are searching for were recently created or
    renamed, in which case
    locate
    may not be
    appropriate.

Refer to
Chapter 6
, for
additional information on the
find
command.

On the Exam

You should have a general understanding of
find
. Remember that by default,
find
prints matching directory entries to the
screen. However, detailed knowledge of
find
options and usage are beyond the scope of LPIC Level 1
exams.

Name

locate

Syntax
locate
patterns
Description

Locate files whose names match one or more
patterns
by searching an index of files
previously created.

Example

Locate files by name in the entire directory hierarchy that
might have something to do with the
csh
shell
or its variants:

#
locate csh
/home/jdean/.tcshrc
/root/.cshrc
/root/.tcshrc
/usr/bin/sun-message.csh
/usr/doc/tcsh-6.08.00
/usr/doc/tcsh-6.08.00/FAQ
/usr/doc/tcsh-6.08.00/NewThings
/usr/doc/tcsh-6.08.00/complete.tcsh
/usr/doc/tcsh-6.08.00/eight-bit.txt
/usr/doc/vim-common-5.3/syntax/csh.vim
/usr/man/man1/tcsh.1
/usr/share/apps/ktop/pics/csh.xpm
/usr/share/apps/ktop/pics/tcsh.xpm
/usr/share/emacs/20.3/etc/emacs.csh
/usr/share/vim/syntax/csh.vim
/usr/src/linux-2.2.5/fs/lockd/svcshare.c
/etc/csh.cshrc
/etc/profile.d/kde.csh
/etc/profile.d/mc.csh
/bin/csh
/bin/tcsh

The
locate
command must have a recent
database to search, and that database must be updated periodically
to incorporate changes in the filesystem. If the database is stale,
using
locate
yields a warning:

#
locate tcsh
locate: warning: database /var/lib/slocate/slocate.db' is more \
than 8 days old
Name

updatedb

Syntax
updatedb [
options
]
Description

Refresh (or create) the
slocate
database in
/var/lib/slocate/slocate.db
.

Option
-e
directories

Exclude a comma-separated list of
directories
from the
database.

Example

Refresh the
slocate
database, excluding
files in temporary locations:

#
updatedb -e "/tmp,/var/tmp,/usr/tmp,/afs,/net,/proc"

updatedb
is typically executed
periodically via
cron
.

Additional options

Some Linux distributions (Debian, for example) come with a
version of
updatedb
that accepts additional
options that can be specified on the command line:

--netpaths=‘
path1 path2
...

Add network
paths
to the
search list.

--prunepaths=‘
path1
path2 ...

Eliminate
paths
from the
search list.

--prunefs=‘
filesystems
...

Eliminate entire types of
filesystems
, such as NFS.

These options modify the behavior of
updatedb
on some Linux systems by prohibiting
the parsing of certain filesystem locations and by adding others.
There are a few more of these options than those listed here, but
these three are special in that they can also be specified through
the use of environment variables set prior to
updatedb
execution. The variables are
NETPATHS
,
PRUNEPATHS
, and
PRUNEFS
. These variables and the options
to
updatedb
are discussed here because this
Objective makes specific mention of
updatedb.conf
, a sort of control file for
updatedb
. Despite its name,
updatedb.conf
isn’t really a configuration
file, but rather a fragment of a Bourne shell script that sets these
environment variables.
Example 7-2
shows a sample
updatedb.conf
file.

Example 7-2. Sample updatedb.conf file

# This file sets environment variables used by updatedb
# filesystems which are pruned from updatedb database:
PRUNEFS="NFS nfs afs proc smbfs autofs auto iso9660"
export PRUNEFS
# paths which are pruned from updatedb database:
PRUNEPATHS="/tmp /usr/tmp /var/tmp /afs /amd /alex"
export PRUNEPATHS
# netpaths which are added:
NETPATHS="/mnt/fs3"
export NETPATHS

In this example, the
PRUNEFS
and
PRUNEPATHS
variables cause
updatedb
to ignore types of filesystems and
particular paths, respectively.
NETPATHS
is used to add network paths from
remote directory
/mnt/fs3
.

updatedb.conf
doesn’t directly control
updatedb
, but eliminates the need for lengthy
options on the
updatedb
command line, which can
make
crontab
files a bit cleaner.

On the Exam

Remember that
updatedb
does not require
configuration to execute. On systems that provide for
configuration,
updatedb.conf
can specify a
few extra options to
updatedb
by way of
environment variables.

Name

whereis

Syntax
whereis [
options
]
filename
Description

whereis
locates source/binary and
manuals sections for specified files.

Example
#
whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
Name

type

Syntax
type [
options
]
filename
Description

type
is not actually a separate
program, but a built-in part of the
bash
shell.
type
will tell you how a
filename
would be interpreted if used as
a command name.

Example
#
type ls
ls is aliased to `ls --color=auto'
#
type grep
grep is hashed (/bin/grep)
#
type foo
-bash: type: foo: not found

On the Exam

You must be familiar with the
FHS concept and the contents of its major
directories. Be careful about the differences between (and reasons
for)
/bin
and
/sbin
, root filesystem and
/usr
filesystem, and locally supplied
commands. Also practice with various file location techniques and
be able to differentiate among them.

Other books

A Perfect Grave by Mofina, Rick
My Life as a Man by Philip Roth
Devil Sent the Rain by Tom Piazza
Hereafter by Tara Hudson
Frozen Hearts by Teegan Loy
Aeroparts Factory by Paul Kater
The Next Best Bride by Kelly Mcclymer
Cassie's Crush by Fiona Foden
Celestial Navigation by Anne Tyler
Sing Down the Moon by Scott O'dell