Dit geeft de verschillen weer tussen de geselecteerde revisie en de huidige revisie van de pagina.
— |
linux:commandos:pathnames_en.html [2018/12/30 17:17] (huidige) |
||
---|---|---|---|
Regel 1: | Regel 1: | ||
+ | <HTML> | ||
+ | |||
+ | <H1>UNIX PATHNAMES</H1> | ||
+ | <H2>1. In Unix, there are 2 types of pathnames:</H2> | ||
+ | <div class="level2"> | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD><TD>afile</TD> | ||
+ | <TD></TD><TD>adir</TD> | ||
+ | <TD></TD><TD><B>Relative</B> pathnames</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD><B>.</B>/afile</TD> | ||
+ | <TD></TD><TD><B>.</B>/adir</TD> | ||
+ | <TD></TD><TD><B>Relative</B> pathnames</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD>/afile</TD> | ||
+ | <TD></TD><TD>/adir</TD> | ||
+ | <TD></TD><TD><B>Absolute</B> pathnames</TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | <BR> | ||
+ | A <B>relative</B> pathname is relative to the <B>current</B> directory.<BR> | ||
+ | Example: | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD><TD>$ pwd<BR>/home/user1</TD> | ||
+ | <TD></TD><TD VALIGN="top"># Which is the current directory?</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD VALIGN="top">$ cd adir</TD> | ||
+ | <TD></TD><TD># Go to directory "adir" relative<BR> | ||
+ | # to the current directory.</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD>$ pwd<BR>/home/user1/adir</TD> | ||
+ | <TD></TD><TD></TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | |||
+ | <BR> | ||
+ | The pathname "<B>.</B>/afile" is also a relative one. See: part 3.<BR> | ||
+ | |||
+ | <BR> | ||
+ | An <B>absolute</B> pathname starts with "<B>/</B>".<BR> | ||
+ | An absolute pathname always refers to the top (/) of the | ||
+ | Unix directory hierarchy.<BR> | ||
+ | There is just <B>1</B> "/afile" in the entire system.<BR> | ||
+ | Example: | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD><TD>$ pwd<BR>/home/user1</TD> | ||
+ | <TD></TD><TD VALIGN="top"># Which is the current directory?</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD>$ cd /adir</TD> | ||
+ | <TD></TD><TD># Go to directory "/adir".</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD>$ pwd<BR>/adir</TD> | ||
+ | <TD></TD><TD></TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | </div> | ||
+ | |||
+ | <H2>2. Some special directories:</H2> | ||
+ | <div class="level2"> | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD><TD><B>.</B></TD> | ||
+ | <TD></TD><TD>the current directory</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD><B>..</B></TD> | ||
+ | <TD></TD><TD>1 directory higher up in the hierarchy</TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | <BR> | ||
+ | At first sight, the directory "<B>.</B>" might appear to be of no use at all. Quite to the contrary!<BR> | ||
+ | Example: | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD> | ||
+ | <TD VALIGN="top">$ cp</TD> | ||
+ | <TD VALIGN="top">/tmp/afile</TD> | ||
+ | <TD VALIGN="top"><B>.</B></TD> | ||
+ | <TD></TD> | ||
+ | <TD># Copy "/tmp/afile" to the<BR> | ||
+ | # current directory.</TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | <BR> | ||
+ | In MS-DOS you could leave out the "<B>.</B>". Not so in Unix! | ||
+ | </div> | ||
+ | |||
+ | <H2>3. Why "./acmd"?</H2> | ||
+ | <div class="level2"> | ||
+ | |||
+ | De pathnames "afile" and "<B>.</B>/afile" are both <B>relative</B> ones.<BR> | ||
+ | When used as an <B>argument</B> after a command word, there is no difference between the two variants.<BR> | ||
+ | Example: | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD><TD VALIGN="top">$ cd</TD> | ||
+ | <TD VALIGN="top">adir</TD> | ||
+ | <TD># Go to directory "adir" relative<BR> | ||
+ | # to the current directory.</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD><TD>$ cd</TD> | ||
+ | <TD><B>.</B>/adir</TD> | ||
+ | <TD># Will do exactly the same.</TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | <BR> | ||
+ | However, when used as a <B>command word</B>, "acmd" and "<B>.</B>/acmd" are not the same at all! | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD> | ||
+ | <TD>$ acmd</TD> | ||
+ | <TD></TD><TD># Search for program "acmd" via $PATH.</TD> | ||
+ | </TR><TR> | ||
+ | <TD></TD> | ||
+ | <TD VALIGN="top">$ <B>.</B>/acmd</TD> | ||
+ | <TD></TD><TD># Execute program "acmd"<BR> | ||
+ | # in the current directory.</TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | <BR> | ||
+ | |||
+ | Note: In Unix (unlike MS-DOS) the current directory isn't part of the search path by default.<BR> | ||
+ | The current directory will only be part of the search path if it is explicitly mentioned in the PATH variable.<BR> | ||
+ | Like this, for example: | ||
+ | |||
+ | <TABLE BORDER="0" CELLPADDING="5"> | ||
+ | <TR> | ||
+ | <TD></TD><TD>$ echo $PATH<BR>/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games</TD> | ||
+ | <TD VALIGN="top"># Check: which is the current search path?</TD> | ||
+ | </TR> | ||
+ | <TD></TD><TD>$ export PATH=$PATH:<B>.</B></TD> | ||
+ | <TD># Modify the PATH variable.</TD> | ||
+ | </TR> | ||
+ | <TD></TD><TD>$ echo $PATH<BR>/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:<B>.</B></TD> | ||
+ | <TD VALIGN="top"># Check: which is the current search path?</TD> | ||
+ | </TR> | ||
+ | </TABLE> | ||
+ | <BR> | ||
+ | |||
+ | (You may choose to incorporate the line <B>export PATH=$PATH:.</B> in "<B>.</B>profile" or "<B>.</B>bash_profile".) | ||
+ | <BR> | ||
+ | <BR> | ||
+ | |||
+ | <B>CAUTION:</B> | ||
+ | <B>Never</B> add "<B>.</B>" to the "<B>root</B>" user's PATH variable!<BR> | ||
+ | This will highly increase chances of inadvertently executing user-programs<BR> | ||
+ | whilst performing system maintenance tasks (Trojan horses). | ||
+ | </div> | ||
+ | |||
+ | <br /> | ||
+ | <br /> | ||
+ | <hr /> | ||
+ | <p> | ||
+ | <FONT SIZE="-3"> | ||
+ | Copyright (C) 2003 Integrated Services; tux4u.nl<BR> | ||
+ | Author: Ing.J.M.Waldorp<BR> | ||
+ | pathnames_en.html 20030403 | ||
+ | </FONT> | ||
+ | </p> | ||
+ | |||
+ | </HTML> | ||