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

Possible Duplicate:
How to add an alias to a command in terminal?

I use the sublime text 2 text editor for developing in Ubuntu. When I want to open a file form the command line, I need to type sublime-text-2 <file-name>.

I would like to be able to tab after sub to get that, but there is sublime-text and subl or something that which also auto-complete.

Is there a way to change or create an alias for the name sublime-text-2 and call it 'sub' or just 'sublime' or even something completely different like 'texta'?

share|improve this question

marked as duplicate by Florian Diesch, Nitin Venkatesh, RobotHumans, jokerdino, htorque Aug 18 '12 at 6:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

@FlorianDiesch Not necessarily a duplicate -- non-alias solutions (as with @LnxSlck's) are perfectly valid. – belacqua Aug 8 '12 at 23:48

Just do this:

sudo ln -s /pathforsublimetext2install/sublime_text /usr/bin/sublime

Also, I recommend that you install sublime text 2 through a PPA, because it will integrate better with Unity/Gnome.

To install this PPA:

sudo add-apt-repository ppa:webupd8team/sublime-text-2 
sudo apt-get update
sudo apt-get install sublime-text
share|improve this answer
That is how i installed it, cheers. – Ben Aug 8 '12 at 23:50
Manually creating symlinks in /usr is not cool. If you must, create them in ~/bin instead. – Sergey Aug 15 '12 at 23:00
Care to explain why is not cool? As defined /usr/bin contains applications for the system's users. Even more /usr/bin is one of the major subdirectories of the /usr directory. It is the directory in which most standard programs are kept, along with on-line manuals and most libraries (i.e., collections of code that are commonly used by programs). – LnxSlck Aug 15 '12 at 23:48

By default, you can get command completion for aliases in bash on Desktop Ubuntu.

For example, here's my scanh alias (which will tab complete) from .bash_aliases:

alias scanh='egrep -v "^ \*|^\/\*|^$" '

You can create an alias for yourself in the same way. E.g.,

alias text2='/pathtofile/sublime-text-2'

You can also, if you prefer, move the blocking commands out of the way.

For instance, if a command called sublet is confounding your tab-completion, the process might look like this:

$ which sublet 
$ ls -la sublet
$ sudo mv /usr/bin/sublet /usr/bin/xsublet

Linking the sublime-text-2 command to something shorter works the same way. Just make sure that the link you create is in your path:

$ echo $PATH
$ ln -s  sublime-text-2 /usr/local/bin/sub

Any of the above directories, /usr/bin/, /usr/sbin, etc., will work. If you have a stand-alone script or binary, you can also move it into the path directly:

$ sudo mv sublime-text-2 /usr/bin/sub
share|improve this answer

I would use the alias command. I put such things in my ~/.bash_alises file, which is called by my ~/.bashrc. You can also put the following in .bashrc, either way it's up to you.

I have lines like this:

alias del='gvfs-trash'                          #I habitually avoid rm
alias def='surfraw google define:'
alias st2='sublime-text-2'

After changing ~/.bash_aliases the first time, type source ~/.bash_aliases. In the future that will be done when you start your computer.


share|improve this answer

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