Sorry, I'd like to ask this in the form of a comment to the selected answer, but I don't have any rep on superuser yet.
The security answer makes sense, but if you put "." in your PATH as the last thing, shouldn't the shell look in the current directory last as it searches for executables, and thus reduce the security risk? If it did search $PATH in order, it would find /bin/ls before it found ./ls.
So, how insecure is it for me to put "." at the end of my $PATH environment variable?
It works as I suggest. Here's how I tested:
First, add "." to the END of your PATH environment variable.
Then, put the following file in some directory, such as ~/dir1/dir2/test_which.rb:
#!/your/path/to/ruby
puts "this file is from the current directory"
And put this file at /usr/bin/test_which.rb
#!/your/path/to/ruby
puts "this file is at /usr/bin/test_which.rb"
Be sure to chmod +x the files so that they're executable.
Now, if you change directory to ~/dir1/dir2, and execute test_which.rb, you'll get the output
this file is at /usr/bin/test_which.rb
Indeed, if you run "which test_which.rb" from anywhere, it should report
/usr/bin/test_which.rb
You can still execute the file in the current directory by typing:
./test_which.rb
ls
will be/usr/bin/ls
and./ls
isn't. There is also the hurdle of if you know how to add.
to the end of your path, you probably have some idea what you are doing. root should never have.
in the path, many systems don't even let root log in anymore.