ch03.xml.pdf
(
477 KB
)
Pobierz
3
Using Your
Unix Account
•
•
•
An environment you can customize.
In this chapter:
• The Unix Filesystem
• Looking Inside Files
with less
• Protecting and
Sharing Files
• Graphical Filesystem
Browsers
• Completing File and
Directory Names
• Changing Your
Password
• Customizing Your
Account
Once you log in, you can use the many facilities that Unix provides. As an
authorized system user, you have an account that gives you:
A place in the Unix filesystem where you can store your files.
A username that identifies you, lets you control access to your files,
and is an address for your email.
The Unix Filesystem
A
file
is the unit of storage in Unix, as in most other systems. A file can
hold anything: text (a report you’re writing, a to-do list), a program, digi-
tally encoded pictures or sound, and so on. All of those are just sequences
of raw data until they’re interpreted by the right program.
In Unix, files are organized into directories. A
dir ectory
is actually a spe-
cial kind of file where the system stores information about other files. You
can think of a directory as a place, so that files are said to be contained
in
directories and you are said to work
inside
a directory. (If you’ve used a
Macintosh or Microsoft Windows computer, a Unix directory is similar to a
folder.)
This section introduces the Unix filesystem. Later sections in this chapter
show how you can look in files and protect them. Chapter 4 has more
information.
42
7 January 2002 13:12
The Unix Filesystem
43
Your Home Directory
When you log in to Unix, you’re placed in a directory called your
home
dir ectory.
This directory, a unique place in the Unix filesystem, contains
the files you use almost every time you log in. In your home directory,
you can make your own files. As you’ll see in a minute, you can also store
your own directories within your home directory. Like folders in a file
cabinet, this is a good way to organize your files.
Your Working Directory
Your
working directory
(also called your current directory) is the directory
you’re currently working in. Every time you log in, your home directory is
your working directory. You may change to another directory, in which
case the directory you move to becomes your working directory.
Unless you tell Unix otherwise, all commands that you enter apply to the
files in your working directory. In the same way, when you create files,
they’re created in your working directory unless you specify another direc-
tory. For instance, if you type the command
pico
report,
the Pico editor is
started on a file named
report
in your working directory. But if you type a
command such as
pico
/home/joan/report,
a
report
file is edited in a dif-
ferent directory—without changing your working directory. You’ll learn
more about this when we cover pathnames later in this chapter.
If you have more than one terminal window open, or you’re logged in on
several terminals at the same time, each session has its own working
directory. Changing the working directory in one session doesn’t affect
others.
The Directory Tree
All directories on a Unix system are organized into a hierarchical structure
that you can imagine as a family tree. The parent directory of the tree (the
directory that contains all other directories) is known as the
root directory
and is written as a forward slash (
/
).
The root contains several directories. Figure 3-1 shows a visual representa-
tion of the top of a Unix filesystem tree: the root directory and some
directories under the root.
7 January 2002 13:12
44
Chapter 3: Using Your Unix Account
/
Root Directory
bin
etc
users
tmp
usr
john
carol
work
work
play
Figur e 3-1. Example of a directory tree
bin, etc, users, tmp,
and
usr
are some of the
subdir ectories
(child directo-
ries) of the root directory. These subdirectories are fairly standard directo-
ries; they usually contain specific kinds of system files. For instance,
bin
contains many Unix programs. Not all systems have a directory named
users.
It may be called
u
or
home,
and/or it may be located in some other
part of the filesystem.
In our example, the parent directory of
users
(one level above) is the root
directory. It has two subdirectories (one level below),
john
and
car ol.
On
a Unix system, each directory has only one parent directory, but it may
have one or more subdirectories.
*
A subdirectory (such as
car ol)
can have
its own subdirectories (such as
work
and
play),
up to a limitless depth for
practical purposes.
To specify a file or directory location, write its
pathname.
A pathname is
like the address of the directory or file in the Unix filesystem. We look at
pathnames in a moment.
On a basic Unix system, all files in the filesystem are stored on disks con-
nected to your computer. It isn’t always easy to use the files on someone
else’s computer or for someone on another computer to use your files.
Your system may have an easier way: a
networked filesystem.
Networked
*
On most Unix systems, the root directory, at the top of the tree, is
its own
parent. Some
systems have another directory above the root.
7 January 2002 13:12
The Unix Filesystem
45
filesystems make a remote computer’s files appear as if they’re part of
your computer’s directory tree. For instance, a computer in Los Angeles
might have a directory named
boston
with some of the directory tree from
a company’s computer in Boston. Or individual users’ home directories
may come from various computers, but all be available on your computer
as if they were local files. The system staff can help you understand and
configure your computer’s filesystems to make your work easier.
Absolute Pathnames
As you saw earlier, the Unix filesystem organizes its files and directories in
an inverted tree structure with the root directory at the top. An
absolute
pathname
tells you the path of directories you must travel to get from the
root to the directory or file you want. In a pathname, put slashes (
/
)
between the directory names.
For example,
/users/john
is an absolute pathname. It locates one (only
one!) directory. Here’s how:
•
•
•
The root is the first “/”
The directory
users
(a subdirectory of
root)
The directory
john
(a subdirectory of
users)
Be sure that you do not type spaces anywhere in the pathname. Figure
3-2 shows this structure.
Root Directory
/
/
bin
etc
users
tmp
usr
users
/users/john
john
carol
john
Figur e 3-2. Absolute path of directory john
work
work
play
In Figure 3-2, you’ll see that the directory
john
has a subdirectory named
work.
Its absolute pathname is
/users/john/work.
7 January 2002 13:12
46
Chapter 3: Using Your Unix Account
The root is always indicated by the slash (/) at the start of the pathname.
In other words,
an absolute pathname always starts with a slash.
Relative Pathnames
You can also locate a file or directory with a
relative pathname.
A relative
pathname gives the location relative to your working directory.
Unless you use an absolute pathname (starting with a slash), Unix
assumes that you’re using a relative pathname. Like absolute pathnames,
relative pathnames can go through more than one directory level by nam-
ing the directories along the path.
For example, if you’re currently in the
users
directory (see Figure 3-2), the
relative pathname to the
carol
directory below is simply
carol.
The rela-
tive pathname to the
play
directory below that is
carol/play.
Notice that neither pathname in the previous paragraph starts with a slash.
That’s what makes them relative pathnames! Relative pathnames start at
the working directory, not the root directory. In other words,
a relative
pathname never starts with a slash.
Pathname puzzle
Here’s a short but important question. The previous example explains the
relative pathname
car ol/play.
What do you think Unix would say about
the pathname
/car ol/play
? (Look again at Figure 3-2.)
Unix would say “No such file or directory.” Why? (Please think about that
before you read more. It’s very important and it’s one of the most com-
mon beginner’s mistakes.) Here’s the answer. Because it starts with a
slash, the pathname
/carol/play
is an absolute pathname that starts from
the root. It says to look in the root directory for a subdirectory named
car ol.
But there is no subdirectory named
carol
one level directly below
the root, so the pathname is wrong. The only absolute pathname to the
play
directory is
/users/carol/play.
Relative pathnames up
You can go up the tree with the shorthand “..” (dot dot) for the parent
directory. As you saw earlier, you can also go down the tree by using sub-
directory names. In either case (up or down), separate each level by a
slash (/).
7 January 2002 13:12
Plik z chomika:
musli_com
Inne pliki z tego folderu:
ch01.xml.pdf
(407 KB)
ch00.xml.pdf
(52 KB)
ch02.xml.pdf
(792 KB)
ch03.xml.pdf
(477 KB)
ch06.xml.pdf
(578 KB)
Inne foldery tego chomika:
5 Livre LINUX Maîtrisez l'administration du système By Ultimatium
BSD & Unix
Cluster
cobaltstrike
Collection_4_E-Books_Linux_Debian
Zgłoś jeśli
naruszono regulamin