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?

2 Answers 2


Use absolute paths for the jar file:

alias dsim='java -jar /path/to/dsim.jar'
  • 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?
    – sion
    Commented Apr 2, 2014 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.
    – grg
    Commented Apr 3, 2014 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 /".

(via https://coderwall.com/p/oqtj8w)

You must log in to answer this question.

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