Somebody covered this above but didn't really explain it well. Unlike in DOS (which you might be more used to) Unix checks what you have set up in PATH when you enter a command. If the directory you are in is not part of the path command then programs wont execute.
It seems counter intuitive at first (at least it did to me) as I just assumed it would check whatever directory I was in in addition to what was in PATH but Unix doesn't. So unless the program is in a directory that part of PATH you need to specify what directory it is in.
The reason why you enter ./ is that the ./ stands for "whatever directory I currently am in."
The first time I wrote a C program and tried running it in C I almost threw my chair through a window because of this issue. Between that and permissions I considered firebombing red hat
Another possibility is to put . in you path. Then you can just type new to run your program. I believe there are some security issues with doing this but I don't recall what they are.
The command to add . in the path is export PATH=$PATH:.
This will hold good only for the current console. To permanently set the path,
add the above line in the .bashrc file
There is an important security related caveat to the tip about adding "." to your $PATH.
Let's say somebody manages to get a program onto your system and it's called "ls". When you run it, it emails your /etc/passwd out somewhere (or does something much worse), and then does the same thing as a real "ls" command. You don't know that you are running a bad ls, and some bad guy somewhere has managed to do something to your system.
The safest way is to prepend your program names with "./" until you can install them into a standard directory such as /usr/local/bin. (My personal preference, as it keeps /bin, /usr/bin, and others, clean of my own strange binaries.)
It isn't much extra to type, and you soon get used to it.
The security issue can be overcome by overlooked if you add the present directory '.' at the end of your $PATH variable after all the standard bin directories. This is because bash looks for the first executable that can be found in the directories pointed to by $PATH and this search is sequential - the order in which you have given the directories.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.