In Linux, the reason you need to use ./
before executing a binary in the current directory is related to the PATH
environment variable. The PATH
variable tells the shell which directories to search for executable files.
The ./
before a command indicates to the shell to look in the current directory for the executable. By default, the current directory (.
) is usually not part of the PATH
for security reasons. If it were, malicious binaries could be disguised with common command names in directories, and you could inadvertently run them.
如欲操作<代码>nerdctl 在没有预先确定<代码>的情况下从任何地点指挥。
Move or Symlink to a Directory in $PATH
:
Most system-wide binaries are stored in directories that are included in the PATH
variable, such as /usr/local/bin
, /usr/bin
, etc. If you move or symlink your binary to one of these directories, you can call it from anywhere without the ./
prefix.
sudo mv nerdctl /usr/local/bin/
OR
sudo ln -s /path/to/your/nerdctl /usr/local/bin/nerdctl
Modify the PATH
Variable:
This is less recommended because it can introduce the security issues mentioned above, but you could add the directory containing nerdctl
to the PATH
variable.
Add this to your ~/.bashrc
or ~/.zshrc
(depending on your shell):
export PATH=$PATH:/path/to/the/directory