Any path1 to the executable file that contains at least one /
works. The presence of a /
character in a command name tells the shell that you are asking it to run a specific file and that you are specifying the specific place where that file is to be found. This is part of the syntax the shell expects; in most other contexts it is acceptable for (relative) paths to contain no /
character.
For an executable that is not in the current directory, that's any path to it at all. There is no way to write the path of a file in another directory without using at least one /
. This makes running files in other directories the simpler case, even though it is less familiar.
Absolute paths--like /mnt/f/C_F/ex
--start with /
.
Relative paths to a file in another directory--C_F/ex
when you are in the /mnt/f
directory--always contain a /
, even though it is not at the beginning. A relative path without a /
is just a filename, identifying a file in the current directory. (The converse is not true though. A relative path may contain a /
yet still refer to a file in the current directory; see below.)
Note that relative paths must still actually refer to the file you want if they are to work, and whether or not a relative path refers to the file you want depends on what directory you are currently in, since the are resolved relative to the current directory.
For an executable that is in the current directory, the shortest relative path does not generally work, because it does not contain a /
. Thus, this is the more complicated case, even though it is more familiar. When you are in the directory where an executable ex
is located, you can't just run ex
, even though ex
is a perfectly good relative path to that executable.
The reason it does not work is that a command name that does not contain a /
is not treated as a relative path or any path. Instead, it is treated as a filename and searched for in the directories listed in $PATH
.2
This is why you use ./ex
when you're in the same directory as ex
. Every directory contains a .
entry that refers to the directory itself. This provides a way to write a relative path that identifies the same file as ex
but has a /
in it and is thus usable as a command name that the shell treats as a path.
A ./
prefix is thus not a special syntax, but simply the second-simplest way to write a relative path to a file in the current directory, and the simplest way to do so of those that contain a /
.
1 In this answer, I use "path" to mean "pathname." This is the most common use of "path," but not the only one. "Path," as I use the term here, should not be confused with the executable search path, which is the collection of directories whose paths are listed, separated by :
characters, in the $PATH
environment variable.
2 Command names that do not contain a /
may also be resolved as non-external commands, such as shell builtins and shell functions.