I found that sometime I use the command to run a command, but sometime I use the ./command to run another command.

What is the difference?

  • I think that this question would become a bit more clear by substituting xx by command and ./xx by ./command. – Exeleration-G Apr 3 '13 at 11:47
  • 1
    @Exeleration-G I'm not sure changing xx to command necessarily makes this clearer. Consider that command itself is a command (a shell builtin). Without special formatting (like "command") to show that command is a metasyntactic variable, I think xx is better. A more common metasyntactic variable is foo, but xx works just as well. – Eliah Kagan Apr 3 '13 at 16:34
  • OK, well, xx is OK for me, too. – Exeleration-G Apr 3 '13 at 17:38

Running xx searches the directories listed in the PATH environment variable for a file called xx. The first executable it finds (whether a binary or a script), it executes. It does not look in the current directory, unless . is listed in PATH, which is not recommended.

Running ./xx runs the file called xx that is located in the current directory, if there is an executable file with that name there.

To run a file by specifying its location, you must include a / symbol. If there is no / in the command (actually, the first word of the command, which is what identifies the name of the file to be executed), it searches PATH for it. If there is a /, then the first word of the command is taken to refer to a specific file by location.

Thus, ./xx is different from xx because of the / that it contains.

Of course, /xx would not work properly--it would try to run a file called xx located in the root directory, /. Because . represents the current directory, ./xx runs xx there.

  • So does it mean that ./xx is same as xx? – hguser Apr 3 '13 at 5:07
  • No, it does not. It is also not what I read in the answer so why this comment? – Rinzwind Apr 3 '13 at 7:13
  • I apologize, I mean if ./xx is the same as xx if the xx script is locatted at the current directory? – hguser Apr 3 '13 at 7:52
  • 1
    @hguser: ./xx and xx would be the same only if your current directory is on the $PATH and there wouldn't be any other executables named xx in dirs in $PATH before your cwd. – unperson325680 Apr 3 '13 at 8:46
  • @hguser if you run which xx and it tells you /usr/bin/xx, then executing xx or cd /usr/bin ; ./xx will do the same... except for aliases or shell functions. For example, ls and cd /bin ; ./ls will probably show differences (the first with colors, the second without colors). That is because probably ls is an alias to ls --color. You can find if xx is an alias or is calling an executable in the disk using type xx. – Carlos Campderrós Apr 3 '13 at 9:05


In Shell prompt we can execute commands... The command are nothing but the name of executable file kept in particular directory such as like : bin, sbin... We can call executable files without specifying the extension name.

user@comp~# command

When we enter command the file is executed kept in such particular directory.

user@comp~# ./command

In this case of using ./command we are calling to executable file that is kept in the current prompt path (Present working Directory). You can get to know your current working directory of shell with command pwd.

  • for deep study...... read about environment variables. – Rahul Raina Nov 20 '15 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.