Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I'm still very new to Ubuntu. I'm using 12.04, and I'd like to know if there is a way to run this program/shell script without typing:


It's kinda tedious and I'm quite lazy. Any help would be appreciated. Thanks.

share|improve this question
You can always give the full path of the file. – muru Sep 22 '14 at 8:32
Thank you @muru, this I know, but it is a program I use often, so I would like to be able to run it with a simple command, not a long file path. – Jonny Sep 22 '14 at 8:33… this will help for idea :) – dedunumax Oct 10 '14 at 5:17

7 Answers 7

You can add /opt/idea/bin to your PATH variable:


After this you can run it with simply

You probably want to add this line in your ~/.bashrc file.

share|improve this answer
also: if you make the script executable, the .sh extension can be left away (assuming you use the shebang at the top of the script). simply "idea" is enough then. – Jacob Vlijm Mar 1 '14 at 8:24
@Jacob: you cannot leave off the extension, as that is part of the executable's file name (this isn't Windows, where magic like that causes other issues). In order to call the script with the name idea, you would have to create a link or alias with that name pointing at the script. – Jonathan Callen Mar 1 '14 at 13:25
@JonathanCallen Callen you certainly can! make the script executable, remove the .sh extension from both the filename and the command to run it, given the fact that you start the script with the shebang #!/bin/bash. – Jacob Vlijm Mar 1 '14 at 15:25
@Jacob what I mean is without renaming the file, you cannot (and it appears this is part of a larger software package, so you shouldn't just rename files) – Jonathan Callen Mar 1 '14 at 21:29
Thanks @Jacob, notice it says "When scripts are installed into a directory in the system PATH". The script is not such script, in fact moving it outside its installation dir is completely unsupported. The Debian packaging rules don't apply here. – janos Mar 1 '14 at 21:55

You can just create symlink. Create it in /usr/local/bin. All you need is to run command:

sudo ln -s /full/path/to/your/file /usr/local/bin/name_of_new_command

After that you should make your file executable:

chmod +x /full/path/to/your/file

Now you should be able to run name_of_new_command at any time in your terminal.

Note that this is good solution only for home usage of Linux.

share|improve this answer
Great thanks. Easiest method! – Jonny Sep 22 '14 at 10:22
Note that you shouldn't place a symlink in /usr/local/bin that points to a script in a private home folder, such as /home/jack/, as only user jack would usually be able to execute it. The symlink will be visible for other users, but not the file it points to. On a single-user system this may not matter, but still, it is "good practice" to place scripts (or links to scripts) that all users can read in /usr/local/bin, and private, self-made scripts (or links to scripts) of a single user in their ~/bin folder. – Malte Skoruppa Sep 22 '14 at 11:27

You can create a function in your ~/.bashrc:

some-name () {
    # or:
    #cd /path/to/your

Or you can create an alias:

alias some-name='/path/to/your/file'
# or  
#alias some-name='cd /path/to/your/; ./file'

In both cases, you can run it by calling:

$ some-name

If the file doesn't depend on where it's running, consider adding it to your ~/bin:

mkdir -p ~/bin
cp /path/to/you/file ~/bin
# or mv /path/to/you/file ~/bin
# or ln -s /path/to/you/file ~/bin

~/bin, if it exists, gets added to your $PATH automatically. Then you directly call file:

$ file

(Bad choice of name though, consider calling it something less generic.)

share|improve this answer
Thank you @muru – Jonny Sep 22 '14 at 8:38
@Oli always give my the five minutes, I tend to add indents. :) It's just annoying as I need to trick the editor to use Ctrl-K for second-level indents. – muru Sep 22 '14 at 8:39
+1 in particular for the solution of adding file to your ~/bin, which is what I usually do (for longer scripts). I'd have probably even put that one at the top :) Aliases are good for shortcuts to commands with certain parameters, e.g., alias l='ls -CF'. Though I have seen much more awesome uses of aliases. I don't tend to declare functions in ~/.bashrc (I prefer to have all my scripts organised in separate files in ~/bin). Though all this is a matter of taste, I guess :) – Malte Skoruppa Sep 22 '14 at 9:19
@MalteSkoruppa I just gave preference to the methods that most easily lend themselves to cd, because the script may depend on the working directory. :) Otherwise, yes, I tend to put files in ~/bin myself. – muru Sep 22 '14 at 9:23

You can create a launcher by using following command:

gnome-desktop-item-edit --create-new <path-where-to-save>. I t will open this window.

enter image description here

Name it whatever you like and in command box type following

sh -c '/opt/idea/bin/' and save it.

Now you can run that file using newly created launcher


You can create a .desktop file with following contents

[Desktop Entry]
Exec=sh -c '/opt/idea/bin/'     
Icon='<path to an icon file if you want>'

Now save it with .desktop extension on any place.

Make it executable with this command chmod a+x <your-desktop-file>

Now double click to open it.

share|improve this answer

We can define a function and a add hotkey by using bind command to call that. Open ~/.bashrc file and add these line to it:

# define function that opens your program in working directory

# bind hotkey to it (<F12>)
bind -x '"\e[24~":"Openprog"'

Now when you press F12, your program will launch.

Note: A quick way to determine the escape code:

Open your terminal and press Ctrl+V. Now press your favorite keyboard shortcut. The correct escape code should appear. Just make sure to replace ^[ with \e before adding the shortcut to, e.g. replace ^[[24~ with \e[24~.

share|improve this answer

We can also run /opt/idea/bin/ file directly using bash_aliases

Open ~/.bashrc file by running,

gedit ~/.bashrc

Remove the # before the lines and save it, so that the lines will look like,

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

Now open ~/.bash_aliases file,

gedit ~/.bash_aliases

Add the below lines in that file and save it,

alias idea='cd /opt/idea/bin && sudo ./'

Finally source the ~/.bashrc file,

source ~/.bashrc

Now you can run /opt/idea/bin/ file directly by,

share|improve this answer

In addition to the other good answers, consider symlinking into ~/.local/bin and adding this directory to your PATH (from within your .bashrc for instance). This method does not require special permissions (unlike symlinking to /usr/local/bin, for instance). This way, you may have a standard directory struction without flooding your $HOME. Read more about this on these questions:

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.