Read LPI Linux Certification in a Nutshell Online
Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger
Tags: #Reference:Computers
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.
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 |
---|---|---|
Vendor-supplied, essential (root | /bin | /sbin |
Vendor-supplied, nonessential | /usr/bin | /usr/sbin |
Locally supplied, nonessential | /usr/local/bin | /usr/local/sbin |
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 thePATH
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.
which
whichcommand
Determine the location ofcommand
and display the full pathname of
the executable program that the shell would launch to execute it.
which
searches only the user’s path.
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 yourPATH
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.
find
findpaths expression
Locate files that match anexpression
starting atpaths
and continuing recursively. Thefind
command has a rich set ofexpression
directives for locating just
about anything in the
filesystem
.
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
-namefilename
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
becausefind
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.
locate
locatepatterns
Locate files whose names match one or morepatterns
by searching an index of files
previously created.
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
updatedb
updatedb [options
]
Refresh (or create) the
slocate
database in
/var/lib/slocate/slocate.db
.
directories
Exclude a comma-separated list ofdirectories
from the
database.
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
.
Some Linux distributions (Debian, for example) come with a
version of
updatedb
that accepts additional
options that can be specified on the command line:
path1 path2
...
’Add networkpaths
to the
search list.
path1
path2 ...
’Eliminatepaths
from the
search list.
filesystems
...
’Eliminate entire types offilesystems
, 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 areNETPATHS
,PRUNEPATHS
, andPRUNEFS
. 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, thePRUNEFS
andPRUNEPATHS
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.
whereis
whereis [options
]filename
whereis
locates source/binary and
manuals sections for specified files.
#whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
type
type [options
]filename
type
is not actually a separate
program, but a built-in part of the
bash
shell.
type
will tell you how afilename
would be interpreted if used as
a command name.
#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.