Linux, Bash: ./?

mikeshn

Senior member
Oct 9, 2001
367
0
0
I always wanted to ask: Why some commands I must start as ./command and some just command?

I think that if I type just command it should be in my path when I type ./command not in my path. Correct?

Example:

[root@localhost sbin]# ./iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
RH-Lokkit-0-50-INPUT all -- anywhere anywhere

[root@localhost sbin]# iptables -L
bash: iptables: command not found
[root@localhost sbin]#


./iptables -> works
iptables -> error

Thanks
M.S.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
. is the current directory. So ./command is the command in the current working directory, where as the shell would look through your $PATH (in order) and execute the first command (the command you typed in, not just any command ;)) it finds. If you have . in your $PATH you should be fine, unless there is a command with the same name earlier in your $PATH.
 

Buddha Bart

Diamond Member
Oct 11, 1999
3,064
0
0
If you have . in your $PATH

Some people consider this a security vulnerability. In and of itself its not, but when combined with some social enginiering it is often used it a local-attack. Of course this probably isn't that big a deal especially if you don't have lots of users on your system, but just for good measure at least make sure to keep "." out of root's path.

bart
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Buddha Bart
If you have . in your $PATH

Some people consider this a security vulnerability. In and of itself its not, but when combined with some social enginiering it is often used it a local-attack. Of course this probably isn't that big a deal especially if you don't have lots of users on your system, but just for good measure at least make sure to keep "." out of root's path.

bart

I actually have . in root's $PATH. It rarely gets used though, because I am fairly used to using the ./.