Ibm Linux Tutorials - Lpi Certification 101 Exam Prep (Release 2), Part 2 - L-Lpir22-a4.pdf
(
446 KB
)
Pobierz
LPI certification 101 exam prep (release
2), Part 2
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Table of Contents
If you're viewing this document online, you can click any of the topics below to link directly to that section.
1. Before you start.........................................................
2. Regular expressions
...................................................
3. FHS and finding files...................................................
4. Process control
.........................................................
5. Text processing.........................................................
6. Kernel modules
.........................................................
7. Summary and resources
..............................................
2
4
8
15
20
26
31
LPI certification 101 exam prep (release 2), Part 2
Page 1 of 32
ibm.com/developerWorks
Presented by developerWorks, your source for great tutorials
Section 1. Before you start
About this tutorial
Welcome to "Basic administration," the second of four tutorials designed to prepare you for
the Linux Professional Institute's 101 exam. In this tutorial, we'll show you how to use regular
expressions to search files for text patterns. Next, we'll introduce you to the Filesystem
Hierarchy Standard (FSH), and then show you how to locate files on your system. Then, we'll
show you how to take full control of Linux processes by running them in the background,
listing processes, detaching processes from the terminal, and more. Next, we'll give you a
whirlwind introduction to shell pipelines, redirection, and text processing commands. Finally,
we'll introduce you to Linux kernel modules.
This particular tutorial (Part 2) is ideal for those who have a good basic knowledge of
bash
and want to receive a solid introduction to basic Linux administration tasks. If you are new to
Linux, we recommend that you complete
Part 1
of this tutorial series first before continuing.
For some, much of this material will be new, but more experienced Linux users may find this
tutorial to be a great way of "rounding out" their basic Linux administration skills.
By the end of this tutorial, you'll have a solid grounding in basic Linux administration and will
be ready to begin learning some more advanced Linux system administration skills. By the
end of this series of tutorials (eight in all), you'll have the knowledge you need to become a
Linux Systems Administrator and will be ready to attain an LPIC Level 1 certification from the
Linux Professional Institute if you so choose.
For those who have taken the
release 1 version
of this tutorial for reasons other than LPI
exam preparation, you probably don't need to take this one. However, if you do plan to take
the exams, you should strongly consider reading this revised tutorial.
About the authors
For technical questions about the content of this tutorial, contact the authors:
•
Daniel Robbins, at
drobbins@gentoo.org
•
Chris Houser, at
chouser@gentoo.org
•
Aron Griffis, at
agriffis@gentoo.org
Residing in Albuquerque, New Mexico,
Daniel Robbins
is the Chief Architect of
Gentoo
Linux
an advanced ports-based Linux metadistribution. Besides writing articles, tutorials, and
tips for the
developerWorks
Linux zone and Intel Developer Services, he has also served as
a contributing author for several books, including
Samba Unleashed
and
SuSE Linux
Unleashed.
Daniel enjoys spending time with his wife, Mary, and his daughter, Hadassah.
You can contact Daniel at
drobbins@gentoo.org.
Chris Houser,
known to his friends as "Chouser," has been a UNIX proponent since 1994
when he joined the administration team for the computer science network at Taylor
University in Indiana, where he earned his Bachelor's degree in Computer Science and
Mathematics. Since then, he has gone on to work in Web application programming, user
interface design, professional video software support, and now Tru64 UNIX device driver
programming at
Compaq.
He has also contributed to various free software projects, most
Page 2 of 32
LPI certification 101 exam prep (release 2), Part 2
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
recently to
Gentoo Linux).
He lives with his wife and two cats in New Hampshire. You can
contact Chris at
chouser@gentoo.org.
Aron Griffis
graduated from Taylor University with a degree in Computer Science and an
award that proclaimed, "Future Founder of a Utopian UNIX Commune." Working towards that
goal, Aron is employed by
Compaq
writing network drivers for Tru64 UNIX, and spending his
spare time plunking out tunes on the piano or developing
Gentoo Linux.
He lives with his wife
Amy (also a UNIX engineer) in Nashua, New Hampshire.
LPI certification 101 exam prep (release 2), Part 2
Page 3 of 32
ibm.com/developerWorks
Presented by developerWorks, your source for great tutorials
Section 2. Regular expressions
What is a regular expression?
A regular expression (also called a "regex" or "regexp") is a special syntax used to describe
text patterns. On Linux systems, regular expressions are commonly used to find patterns of
text, as well as to perform search-and-replace operations on text streams.
Glob comparison
As we take a look at regular expressions, you may find that regular expression syntax looks
similar to the filename "globbing" syntax that we looked at in Part 1. However, don't let this
fool you; their similarity is only skin deep. Both regular expressions and filename globbing
patterns, while they may look similar, are fundamentally different beasts.
The simple substring
With that caution, let's take a look at the most basic of regular expressions, the
simple
substring.
To do this, we're going to use
grep,
a command that scans the contents of a file
for a particular regular expression.
grep
prints every line that matches the regular
expression, and ignores every line that doesn't:
$ grep bash /etc/passwd
operator:x:11:0:operator:/root:/bin/bash
root:x:0:0::/root:/bin/bash
ftp:x:40:1::/home/ftp:/bin/bash
Above, the first parameter to
grep
is a regex; the second is a filename.
Grep
read each line
in /etc/passwd and applied the simple substring regex
bash
to it, looking for a match. If a
match was found,
grep
printed out the entire line; otherwise, the line was ignored.
Understanding the simple substring
In general, if you are searching for a substring, you can just specify the text verbatim without
supplying any "special" characters. The only time you'd need to do anything special would be
if your substring contained a
+, ., *, [, ],
or
\,
in which case these characters would need to
be enclosed in quotes and preceded by a backslash. Here are a few more examples of
simple substring regular expressions:
•
•
•
•
/tmp
(scans for the literal string
/tmp)
"\[box\]"
(scans for the literal string
[box])
"\*funny\*"
(scans for the literal string
*funny*)
"ld\.so"
(scans for the literal string
ld.so)
Metacharacters
Page 4 of 32
LPI certification 101 exam prep (release 2), Part 2
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
With regular expressions, you can perform much more complex searches than the examples
we've looked at so far by taking advantage of metacharacters. One of these metacharacters
is the
.
(a period), which matches any single character:
$ grep dev.hda /etc/fstab
/dev/hda3
/
/dev/hda1
/boot
/dev/hda2
swap
#/dev/hda4
/mnt/extra
reiserfs
reiserfs
swap
reiserfs
noatime,ro 1 1
noauto,noatime,notail 1 2
sw 0 0
noatime,rw 1 1
In this example, the literal text
dev.hda
didn't appear on any of the lines in /etc/fstab.
However,
grep
wasn't scanning them for the literal
dev.hda
string, but for the
dev.hda
pattern.
Remember that the
.
will match
any single character.
As you can see, the
.
metacharacter is functionally equivalent to how the
?
metacharacter works in "glob"
expansions.
Using []
If we wanted to match a character a bit more specifically than
.,
we could use
[
and
]
(square brackets) to specify a subset of characters that should be matched:
$ grep dev.hda[12] /etc/fstab
/dev/hda1
/boot
/dev/hda2
swap
reiserfs
swap
noauto,noatime,notail 1 2
sw 0 0
As you can see, this particular syntactical feature works identically to the
[]
in "glob"
filename expansions. Again, this is one of the tricky things about learning regular
expressions -- the syntax is
similar but not identical
to "glob" filename expansion syntax,
which often makes regexes a bit confusing to learn.
Using [^]
You can reverse the meaning of the square brackets by putting a
^
immediately after the
[.
In this case, the brackets will match any character that is
not
listed inside the brackets.
Again, note that we use
[^]
with regular expressions, but
[!]
with globs:
$ grep dev.hda[^12] /etc/fstab
/dev/hda3
/
#/dev/hda4
/mnt/extra
reiserfs
reiserfs
noatime,ro 1 1
noatime,rw 1 1
Differing syntax
It's important to note that the syntax
inside
square brackets is fundamentally different from
that in other parts of the regular expression. For example, if you put a
.
inside square
brackets, it allows the square brackets to match a literal
.,
just like the
1
and
2
in the
examples above. In comparison, a literal
.
outside the square brackets is interpreted as a
metacharacter unless prefixed by a
\.
We can take advantage of this fact to print a list of all
lines in /etc/fstab that contain the literal string
dev.hda
by typing:
LPI certification 101 exam prep (release 2), Part 2
Page 5 of 32
Plik z chomika:
musli_com
Inne pliki z tego folderu:
(Linux-Test-English) LPI 117-102, General Linux Q&A v1.0 (TestKing.com).pdf
(285 KB)
117-101.pdf
(121 KB)
117-102.pdf
(335 KB)
2_LPI-Linux Certification in a nutshell2001.pdf
(2448 KB)
ActualTests.LPI.117-101.v03.29.04.pdf
(292 KB)
Inne foldery tego chomika:
CloudStack
distribution
dsp
electronics
network
Zgłoś jeśli
naruszono regulamin