Ibm Linux Tutorials - Lpi Certification 101 Exam Prep Part 1.pdf

(1006 KB) Pobierz
LPI certification 101 exam prep, Part 1
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. About this tutorial.......................................................
2. Introducing bash........................................................
3. Using Linux commands
...............................................
4. Creating links and removing files
....................................
5. Introducing wildcards
..................................................
6. Resources and feedback
.............................................
2
3
7
12
16
19
LPI certification 101 exam prep, Part 1
Page 1 of 20
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 1. About this tutorial
What does this tutorial cover?
Welcome to "Linux fundamentals", the first of four tutorials designed to prepare you for the
Linux Professional Institute's 101 exam. In this tutorial, we'll introduce you to
bash
(the
standard Linux shell), show you how to take full advantage of standard Linux commands like
ls, cp,
and
mv,
explain Linux's permission and ownership model, and much more.
By the end of this tutorial, you'll have a solid grounding in Linux fundamentals and will even
be ready to begin learning some basic Linux system administration tasks.
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.
The LPI logo is a trademark of Linux Professional Institute.
Should I take this tutorial?
This tutorial (Part 1) is ideal for those who are new to Linux, or those who want to review or
improve their understanding of fundamental Linux concepts, such as copying files, moving
files, and creating symbolic and hard links. Along the way, we'll share plenty of hints, tips,
and tricks to keep the tutorial "meaty" and practical, even for those with a good amount of
previous Linux experience. For beginners, 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
fundamental Linux skills.
Also in this series are three other tutorials:
*
Part 2: Basic administration
*
Part 3: Intermediate administration
*
Part 4: Advanced administration
About the author
For technical questions about the content of this tutorial, contact the author, Daniel Robbins,
at
drobbins@gentoo.org.
Residing in Albuquerque, New Mexico, Daniel Robbins is the President/CEO of
Gentoo
Technologies, Inc.,
the creator of
Gentoo Linux,
an advanced Linux for the PC, and the
Portage
system, a next-generation ports system for Linux. He has also served as a
contributing author for the Macmillan books
Caldera OpenLinux Unleashed, SuSE Linux
Unleashed,
and
Samba Unleashed.
Daniel has been involved with computers in some
fashion since the second grade, when he was first exposed to the Logo programming
language as well as a potentially dangerous dose of Pac Man. This probably explains why he
has since served as a Lead Graphic Artist at
SONY Electronic Publishing/Psygnosis.
Daniel enjoys spending time with his wife, Mary, and his new baby daughter, Hadassah.
LPI certification 101 exam prep, Part 1
Page 2 of 20
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 2. Introducing bash
The shell
If you've used a Linux system, you know that when you log in, you are greeted by a prompt
that looks something like this:
$
The particular prompt that you see may look quite different. It may contain your system's
hostname, the name of the current working directory, or both. But regardless of what your
particular prompt may look like, there's one thing that's certain. The program that printed that
prompt is called a "shell", and it's very likely that your particular shell is a program called
bash.
Are you running bash?
You can check to see if you're running
bash
by typing:
$ echo $SHELL
/bin/bash
If the above line gave you an error or didn't respond similarly to our example, then you may
be running a shell other than
bash.
In that case, most of this tutorial should still apply, but it
would be advantageous for you to switch to
bash
for the sake of preparing for the 101 exam.
(See Part 2 of this tutorial series for information on changing your shell using the
chsh
command.)
About bash
Bash, an acronym for "Bourne-again shell", is the default shell on most Linux systems. The
shell's job is to obey your commands so that you can interact with your Linux system. When
you're finished entering commands, you may instruct the shell to
exit
or
logout,
at which
point you'll be returned to a login prompt.
By the way, you can also logout by pressing control-D at the
bash
prompt.
Using "cd"
As you've probably found, staring at your
bash
prompt isn't the most exciting thing in the
world. So, let's start using
bash
to navigate around our filesystem. At the prompt, type the
following (without the
$):
$ cd /
We've just told
bash
that you want to work in /, also known as the
root
directory; all the
directories on the system form a tree, and / is considered the top of this tree, or the root.
cd
LPI certification 101 exam prep, Part 1
Page 3 of 20
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
sets the directory where you are currently working, also known as the "current working
directory".
Paths
To see bash's current working directory, you can type:
$ pwd
/
In the above example, the / argument to
cd
is called a
path.
It tells
cd
where we want to go.
In particular, the / argument is an
absolute
path, meaning that it specifies a location relative
to the root of the filesystem tree.
Absolute paths
Here are some other absolute paths:
/dev
/usr
/usr/bin
/usr/local/bin
As you can see, the one thing that all absolute paths have in common is that they begin with
/. With a path of /usr/local/bin, we're telling
cd
to enter the / directory, then the usr directory
under that, and then local and bin. Absolute paths are always evaluated by starting at / first.
Relative paths
The other kind of path is called a
relative path.
Bash,
cd,
and other commands always
interpret these paths relative to the current directory. Relative paths never begin with a /. So,
if we're in /usr:
$ cd /usr
Then, we can use a relative path to change to the /usr/local/bin directory:
$ cd local/bin
$ pwd
/usr/local/bin
Using ".."
Relative paths may also contain one or more .. directories. The .. directory is a special
directory that points to the parent directory. So, continuing from the example above:
$ pwd
LPI certification 101 exam prep, Part 1
Page 4 of 20
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
/usr/local/bin
$ cd ..
$ pwd
/usr/local
As you can see, our current directory is now /usr/local. We were able to go "backwards" one
directory, relative to the current directory that we were in.
Using "..", continued
In addition, we can also add .. to an existing relative path, allowing us to go into a directory
that's alongside one we are already in, for example:
$ pwd
/usr/local
$ cd ../share
$ pwd
/usr/share
Relative path examples
Relative paths can get quite complex. Here are a few examples, all without the resultant
target directory displayed. Try to figure out where you'll end up after typing these commands:
$ cd /bin
$ cd ../usr/share/zoneinfo
$ cd /usr/X11R6/bin
$ cd ../lib/X11
$ cd /usr/bin
$ cd ../bin/../bin
Now, try them out and see if you got them right. :)
Understanding "."
Before we finish our coverage of
cd,
we need to discuss a few more things. First, there is
another special directory called
.,
which means "the current directory". While this directory
isn't used with the
cd
command, it's often used to execute some program in the current
directory, as follows:
$ ./myprog
In the above example, the
myprog
executable residing in the current working directory will
be executed.
LPI certification 101 exam prep, Part 1
Page 5 of 20
Zgłoś jeśli naruszono regulamin