Gebruikershulpmiddelen

Site-hulpmiddelen


linux:commandos:pathnames_en.html

UNIX PATHNAMES

1. In Unix, there are 2 types of pathnames:

afile adir Relative pathnames
./afile ./adir Relative pathnames
/afile /adir Absolute pathnames

A relative pathname is relative to the current directory.
Example:
$ pwd
/home/user1
# Which is the current directory?
$ cd adir # Go to directory "adir" relative
# to the current directory.
$ pwd
/home/user1/adir

The pathname "./afile" is also a relative one. See: part 3.

An absolute pathname starts with "/".
An absolute pathname always refers to the top (/) of the Unix directory hierarchy.
There is just 1 "/afile" in the entire system.
Example:
$ pwd
/home/user1
# Which is the current directory?
$ cd /adir # Go to directory "/adir".
$ pwd
/adir

2. Some special directories:

. the current directory
.. 1 directory higher up in the hierarchy

At first sight, the directory "." might appear to be of no use at all. Quite to the contrary!
Example:
$ cp /tmp/afile . # Copy "/tmp/afile" to the
# current directory.

In MS-DOS you could leave out the ".". Not so in Unix!

3. Why "./acmd"?

De pathnames "afile" and "./afile" are both relative ones.
When used as an argument after a command word, there is no difference between the two variants.
Example:
$ cd adir # Go to directory "adir" relative
# to the current directory.
$ cd ./adir # Will do exactly the same.

However, when used as a command word, "acmd" and "./acmd" are not the same at all!
$ acmd # Search for program "acmd" via $PATH.
$ ./acmd # Execute program "acmd"
# in the current directory.

Note: In Unix (unlike MS-DOS) the current directory isn't part of the search path by default.
The current directory will only be part of the search path if it is explicitly mentioned in the PATH variable.
Like this, for example:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
# Check: which is the current search path?
$ export PATH=$PATH:. # Modify the PATH variable.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:.
# Check: which is the current search path?

(You may choose to incorporate the line export PATH=$PATH:. in ".profile" or ".bash_profile".)

CAUTION: Never add "." to the "root" user's PATH variable!
This will highly increase chances of inadvertently executing user-programs
whilst performing system maintenance tasks (Trojan horses).



Copyright (C) 2003 Integrated Services; tux4u.nl
Author: Ing.J.M.Waldorp
pathnames_en.html 20030403

linux/commandos/pathnames_en.html.txt · Laatst gewijzigd: 2018/12/30 17:17 (Externe bewerking)