Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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