Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I've got an executable, let's call it exec. It lives in a directory, for the sake of argument called dir. Let's say it's at the filesystem root. I can run this executable by doing

cd /dir

If I try to run it from anywhere else, by doing


it fails to run. From the error message it spews out, it looks like it's trying to look for support files in the directory from which the command was run, not in its own directory. So far not a massive problem. However, I'd like to alias the command so I can call it from anywhere. I can write an alias as follows:

alias foo="cd /dir;./exec &"

But that leaves my terminal in /dir, which I don't want. I also don't want to change back to some arbitrary directory, I want to stay where I was.

Can this be done?

share|improve this question
up vote 7 down vote accepted

Yes, launch another shell:

alias foo="sh -c 'cd /dir; ./exec &'"

Or use a subshell:

alias foo="(cd /dir; ./exec &)"
share|improve this answer
Thanks. Works perfectly. – TimD Jan 19 '13 at 13:19

You can also do like this: suppose the file to execute anywhere is named: executeme

  1. If it is not a executable file type the following command to maike it excutable

chmod +x executeme

  1. If you are in the directory where the file is make a symbolic link to it in the bin directory(you must be root to do this)

sudo ln -s executeme /usr/bin/

  1. If all is right you can now exute your file anywhere by typing the name of the file


share|improve this answer

Your Answer


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.