[ Pobierz całość w formacie PDF ]

very important and it's one of the most common 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 carol. 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.
3.1.5.2 Relative pathnames up
You can go up the tree by using the shorthand ".." (dot dot) for the parent directory. As you saw above,
you can also go down the tree by using subdirectory names. In either case (up or down), separate each
level by a slash (/).
Figure 3.3 shows a part of Figure 3.1. If your working directory in the figure is work, there are two
pathnames for the play subdirectory of carol. You already know how to write the absolute pathname,
/users/carol/play. You can also go up one level (with "..") to carol, then go down the tree to play. Figure
3.3 shows that.
Figure 3.3: Relative pathname from work to play
Figure 3.3
file:///C|/Documents%20and%20Settings/nmyers/Desktop/learn_unix/ch03_01.htm (4 of 10) [6/30/2002 3:41:09 PM]
[Chapter 3] Your UNIX Account
The relative pathname would be ../play. It would be wrong to give the relative address as carol/play.
Using carol/play would say that carol is a subdirectory of your working directory instead of what it is in
this case: the parent directory.
Absolute and relative pathnames are totally interchangeable. UNIX commands simply follow whatever
path you specify to wherever it leads. If you use an absolute pathname, the path starts from the root. If
you use a relative pathname, the path starts from your working directory. Choose whichever is easier at
the moment.
3.1.6 Changing Your Working Directory
When you know the absolute or relative pathname of a directory, you can move up and down the UNIX
directory tree.
3.1.6.1 pwd
To find which directory you're currently in, use the pwd (print working directory) command. The pwd
command takes no arguments.
% pwd
/users/john
%
pwd prints the absolute pathname of your working directory.
3.1.6.2 cd
You can change your working directory to any directory (including another user's directory - if you have
permission) with the cd (change directory) command.
The cd command has the form:
cd pathname
The argument is an absolute or a relative pathname (whichever is easier) for the directory you want to
change to.
% cd /users/carol
% pwd
/users/carol
% cd work
file:///C|/Documents%20and%20Settings/nmyers/Desktop/learn_unix/ch03_01.htm (5 of 10) [6/30/2002 3:41:09 PM]
[Chapter 3] Your UNIX Account
% pwd
/users/carol/work
%
Here's a handy tip: the command cd, with no arguments, takes you to your home directory from wherever
you are in the filesystem.
Note that you can only change to another directory. You cannot cd to a filename. If you try, UNIX will
give you an error message:
% cd /etc/passwd
/etc/passwd: Not a directory
%
/etc/passwd is a file that contains information about users allowed to log in to the system.
3.1.7 Files in the Directory Tree
A directory can hold subdirectories. And, of course, a directory can hold files. Figure 3.4 is a close-up of
the filesystem around john's home directory. The four files are shown along with the work subdirectory.
Figure 3.4: Files in the directory tree
Figure 3.4
Pathnames to files are made the same way as pathnames to directories. For example, if your working
directory is users, the relative pathname to the work directory below would be john/work. The relative
pathname to the ch1 file would be john/ch1.
3.1.8 Listing Files
To use the cd command, you must decide which entries in a directory are subdirectories and which are
files. The ls command lists the entries in the directory tree.
3.1.8.1 ls
When you enter the ls command, you'll get a listing of the files and subdirectories contained in your
working directory. The syntax is:
ls option(s) directory-and-filename(s)
file:///C|/Documents%20and%20Settings/nmyers/Desktop/learn_unix/ch03_01.htm (6 of 10) [6/30/2002 3:41:09 PM]
[Chapter 3] Your UNIX Account
If you've just logged in for the first time, entering ls without any arguments may seem to do nothing. This
isn't surprising because you haven't made any files in your working directory. If you have no files,
nothing is displayed; you'll simply get a new shell prompt.
% ls
%
But if you've already made some files or directories in your account, those names are displayed. The
output depends on what's in your directory. The display should look something like this:
% ls
ch1 ch10 ch2 ch3 intro
%
(Some systems display filenames in a single column. If yours does, you can change the display to
columns with the -x option.) ls has a lot of options that change the information and display format.
The -a option (for all) is guaranteed to show you some more files, as in the following example:
% ls -a
. .exrc ch1 ch2 intro
.. .profile ch10 ch3
%
You'll always see at least two new entries with the names "." (dot) and ".." (dot dot). As mentioned
earlier, .. is always the relative pathname to the parent directory, and a single . always stands for any
working directory. There may also be other files, like .profile or .exrc. Any entry whose name begins
with a dot is hidden - it will be listed only if you use ls -a.
To get more information about each file, add the -l option. (That's a lowercase letter "L" for long.) This
option can be used alone, or in combination with -a, as shown in Figure 3.5.
Figure 3.5: Output from ls -al
Figure 3.5
The long format provides the following information about each file:
Total n
n amount of storage used by the files in this directory.
file:///C|/Documents%20and%20Settings/nmyers/Desktop/learn_unix/ch03_01.htm (7 of 10) [6/30/2002 3:41:09 PM]
[Chapter 3] Your UNIX Account
Type [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • gim1chojnice.keep.pl