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 have a whole bunch of aliased commands in .bash_aliases

The most generic examples are

alias apt-update="sudo apt-get update"  
alias apt-upgrade="sudo apt-get dist-upgrade"

but then I also have

alias apt-install="sudo apt-get install "
alias a2avail="/etc/apache2/sites-available"

The first two are no issue, The second two I want to make the more powerful;

Specifically for apt-install I want autocomplete to work.

for a2avail I want to be able to type something like sudo cp a2avail/default a2avail/new and have it run as sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/new

are either of these two things possible?

share|improve this question
There is a generic script for doing it to all alias here:… – brandizzi May 26 at 14:47
up vote 4 down vote accepted

Adding the following to your ~/.bashrc should complete packagenames for your apt-install alias

_apt_install_complete() { 
    mapfile -t COMPREPLY < <(apt-cache --no-generate pkgnames "$2");
complete -F _apt_install_complete apt-install

As for a2avail, an alias will only work as the first word of a command, but you can use a variable.

a2avail=/etc/apache2/sites-available   # in ~/.bashrc

# then...
sudo cp "$a2avail"/{default,new}
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.