Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I run a program without cd'ing to the directory where it resides?

I have tried ./my/dir myfile.pl and again without the leading . but neither work.

share|improve this question
up vote 6 down vote accepted

You enter the full path of the executable:

./path/to/my/dir/myfile.pl
share|improve this answer
    
The file will still be ran from the directory you are currently in. keep that in mind. – UtahJarhead Oct 3 '12 at 18:15

Two dots solves the problem, one dot generates an error (on debian at least) as in the example below:

../usr/local/bin/myprogram

share|improve this answer
1  
Two dots do not 'solve the problem'. The dot refers to the current directory, two dots refer to the parent; they are different paths, one of which may or may not be the one you seek. Depending on the current directory, your example may work, but I believe you're looking for the more general /usr/local/bin/myprogram. – Marcks Thomas Nov 18 '13 at 14:57
1  
whatever directory i am in, one dot 'generates a bash' error! – BurakT Nov 18 '13 at 15:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .