The literal answer is as others have given: because the current directory isn't in your $PATH
.
But why? In short, it's for security. If you're looking in someone else's home directory (or /tmp), and type just gcc
or ls
, you want to know you're running the real one, not a malicious version your prankster friend has written which erases all your files. Another example would be test
or [
, which might override those commands in shell scripts, if your shell doesn't have those as built-ins.
Having .
as the last entry in your path is a bit safer, but there are other attacks which make use of that. An easy one is to exploit common typos, like sl
or ls-l
. Or, find a common command that happens to be not installed on this system — vim
, for example, since sysadmins are of above-average likelyhood to type that.
Does this sound too theoretical? It largely is, but it definitely can happen in reality, especially on multi-user systems. In fact, here is an example from this site where an administrator switched to a users' home directory and found ps
to be masked by an executable of that name.
How can i run a downloaded file?
How can i run a downloaded file?
How to run .bin file?
How to run .bin file?