When you type the name of a program such as a.out
the system looks for the file in your PATH. On my system, PATH is set to
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Yours is probably similar. To check, enter echo $PATH
in a terminal.
The system looks through these directories in the order given and if it can't find the program produces a command not found
error.
Prepending the command with ./
effectively says "forget about the PATH, I want you to look only in the current directory".
Similarly you can tell the system to look in only another specific location by prepending the command with a relative or absolute path such as:
../
means in the parent directory eg ../hello
look for hello in the parent directory.
./Debug/hello
: "look for hello
in the Debug subdirectory of my current directory."
or /bin/ls
: "look for ls
in the directory /bin
"
By default, the current directory is not in the path because it's considered a security risk. See Why is . not in the path by default? on Superuser for why.
It's possible to add the current directory to your PATH, but for the reasons given in the linked question, I would not recommend it.
There is no way to find out now. You probably have a setting in ~/.bashrc
that intentionally hides all commands prepending with a space from history. To change this behaviour in the future, you can edit ~/.bashrc
. Look for this line
HISTCONTROL=ignoredups:ignorespace
and change it to
HISTCONTROL=ignoredups
Best Answer
Do you want it to work without typing an extra command, e.g.
Or only when the user types something like
Or only when the user tries to run certain commands, e.g.
but not for
If option 1, that can be done using the preexec hook in zsh, or the DEBUG trap in bash.
If option 2, put something like this in
/etc/bash.bashrc
or other shell startup file.If option 3, you could modify the
confirm
script above, or, some commands have an option to ask before doing something, e.g.rm -i
. You could putalias rm='rm -i'
in/etc/bash.bashrc
.