Ask Different is a question and answer site for power users of Apple hardware and software. 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 have a java tool that I use quite often from the command line but to use it I have to type java -jar dsim.jar. I want to make it so that I can call it just by typing dsim regardless of what directory I am in, but I can't quite work out how to accomplish this.

I have created a file at ~/.bash_profile and put into it:

alias dsim='java -jar dsim.jar'

And I have placed the dsim.jar file into /usr/local/bin as I read this is where user created command line tools should be kept. This location is in my $PATH.

I think the alias works well but location of the file doesn't seem to be accessible from anywhere. If I call dsim from within /usr/local/bin it works fine but if I am in any other directory I get:

Error: Unable to access jar file dsim.jar

How can I get this to work from any directory?

share|improve this question

Use absolute paths for the jar file:

alias dsim='java -jar /path/to/dsim.jar'
share|improve this answer
That will probably work but isn't the idea of putting something into a directory in your PATH that you don't have to address it like that? I thought that having it in the PATH meant that you could call just the filename from any directory and it would be found? – Sam Apr 2 '14 at 23:42
@Sam Not for files like this. java is located using the PATH, but files are not, otherwise if you had a file called java in a folder then running a command such as cp java java2 would copy the file from your PATH rather than the file in the current folder. – grgarside Apr 3 '14 at 20:51

This is not a direct answer, but you can consider the following solution as an useful one for often repeated commands:

Create ~/.inputrc and fill it with this:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

This allows you to search through your history using the up and down arrows … i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /".


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.