📄 203-206.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Configuration and Installation:Basic Linux Tools</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=1558285660//-->
<!--TITLE=Linux Configuration and Installation//-->
<!--AUTHOR=Patrick Volkerding//-->
<!--AUTHOR=Kevin Reichard//-->
<!--AUTHOR=Eric Foster//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=4//-->
<!--PAGES=203-206//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="200-203.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="206-208.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Your Home Directory</B></FONT></P>
<P>When you set up a user account in Chapter 2, you also created a <I>home</I> directory for the user (in this case, you). You can think of your home directory as a base for operations. When you login the system, you’re automatically placed in this directory, and default files for important applications (such as <B>emacs</B>) have been automatically been copied to this directory. Generally, it’s a good idea to name the directory the same as the login name of the user; in Chapter 2, for example, the home directory was named <B>kevinr</B>. The absolute filename of this home directory is <B>/home/kevinr</B>.</P>
<P>You should keep all your files in your home directory. In fact, the default Linux installation gives you no choice other than to store your files in this directory, as file permissions don’t allow you to write to any other directories. (The root user, on the other hand, can do anything to any directory.) You can create subdirectories, however, to better help you organize the many files that you’ll inevitably create as a result of your Linux usage.</P>
<P>You can <I>always</I> use the tilde character (<B>~</B>) as a shortcut for the home directory, as you’ll see in the following commands.</P>
<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Moving Between Directories with Cd</FONT></H4>
<P>At any given time, you can be placed in only one directory, which is your <I>current</I> or <I>working</I> directory. If you visualize the directory scheme as a hierarchy, you can also visualize moving between various parts of that hierarchy. The Linux command that allows you to move between directories is <B>cd</B>. You can use to the <B>cd</B> command to point to a specific directory:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/$ cd /usr
gilbert:/usr$
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>The Bourne Again SHell, or <B>bash</B>, is set up by default on Linux systems. <B>Bash</B> is designed to show the name of the machine on a prompt (in this instance, <I>gilbert</I>), as well as the current directory. (A colon is used to separate the machine name and the current directory.) As you can see in the previous example, the first line shows that the current directory is <TT>/</TT>, or the root directory. In the second line—after running the <B>cd</B> command—the current directory is <B>/usr</B>.<HR></FONT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>We’re getting ahead of ourselves here a bit, diving into UNIX commands without every really describing them. For now, suffice it to say that a <I>command</I> is a direct instruction to the Linux system.<HR></FONT>
</BLOCKQUOTE>
<P>The <B>cd</B> command can be used in many different ways. You can use it to make the root directory your current directory:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr$ cd /
gilbert:/$
</PRE>
<!-- END CODE SNIP //-->
<P>You can also use it to move up a single directory in the hierarchy. In the next example, your current directory is <B>/usr/doc</B> and you want to make the <B>/usr</B> directory your current directory. To do this, you’ll need to know that Linux always represents the current directory with a period (<TT>.</TT>) and the parent directory with two periods (<TT>..</TT>). The following command line, then, would move your current directory to the parent directory:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr/doc$ cd ..
gilbert:/usr$
</PRE>
<!-- END CODE SNIP //-->
<P>The explanation probably made this example seem more complex than it is.
</P>
<P>You can also use <B>cd</B> to make a subdirectory your current directory. The trick here is knowing that you’ll want to move to a directory relative to your current directory. Knowing that <B>doc</B> is a subdirectory of the current directory <B>/usr</B>, you would move to the <B>doc</B> directory with the following command line:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr$ cd doc
gilbert:/usr/doc$
</PRE>
<!-- END CODE SNIP //-->
<P>However, if you used the following command line, you’d experience failure:
</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr$ cd /doc
bash: /doc: No such file or directory
</PRE>
<!-- END CODE SNIP //-->
<P>You’re generating this error message because <B>doc</B> and <B>/doc</B> would be two different directories—<B>doc</B> exists as a subdirectory of the current directory, while <B>/doc</B> would need to be a subdirectory of the root directory (hence the leading slash). Beginners are sometimes confused by this point.</P>
<P>Another command line that would generate a failure is:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:~$ cd..
bash: cd..: not found
</PRE>
<!-- END CODE SNIP //-->
<P>Without the space between the <B>cd</B> command and the notation for the higher-level command, the shell doesn’t understand your request.</P>
<P>You can also move to your home directory at any time, no matter what the current directory is, with the following command:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr$ cd ~
gilbert:~$
</PRE>
<!-- END CODE SNIP //-->
<P>The tilde (<B>~</B>) symbol can be used at any time and in other commands as shorthand for your home directory. In addition, using <B>cd</B> without a new directory specification will automatically lead you to your home directory:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr$ cd
gilbert:~$
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING: </B>There’s really only one restriction to the <B>cd</B> command: You must have execute permission for the directory you’re switching to.<HR></FONT>
</BLOCKQUOTE>
<P>If you decide to go with another Linux shell that <I>doesn’t</I> list the current directory (see “Linux Shells,” later in this chapter) at the beginning of the prompt, you’ll need to use the <B>pwd</B> (short for <I>print working directory</I>) command to print the name of the current working directory:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/usr$ pwd
/usr
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="200-203.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="206-208.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -