The dot refers to the current directory. The forward slash “/” is the directory path separator.
So, when you type in
./filename at the shell, you prefix the filename with the path to the current directory.
Why do we need to do this when running any executable file?
When you run a command in the shell, it either runs it as a built-in command, or as an executable.
If it isn’t a built-in command, the shell tries looking for the executable in all the directories specified by the
PATH environment variable – you can see what this contains by typing in
echo $PATH in the terminal.
So if your file is in the current directory, the shell won’t find it – because the current directory is not included in the
PATH by default. If you prefix the dot and the slash, the path to the file is passed to the shell, which looks for it exactly at the specified location. In fact, the shell doesn’t search the
PATH at all when an absolute or relative path (other than just the filename) is specified.
Here’s something to try, but make sure you immediately undo it by exiting the terminal: Add the current directory to the
PATH variable in your current shell by typing in
Now, you can run your executable without the dot slash!
WARNING: As noted in the comments below, this change has security implications. The above command will last only for the current terminal session – the changes to the PATH variable will be lost when you exit the terminal. Make sure you do not make this change permanent.
How about using the absolute path?
Since the dot slash helps the shell find the executable by specifying the directory, providing the absolute path without the dot prefix also works.
People might think you always need the dot to be prefixed, even when using absolute paths, but that doesn’t work because you end up prefixing the path to the current directory in addition to the complete path.
Note that you can also execute files using a relative path, in the form of
<sub-dir>/<executable>, for example.