apt-get shortcut commands in ubuntu

This is something useful that I discovered last week. It allows you to use shortcuts (aliases) for long commands that you type often. For example, it is much easier and faster to type “agi <package name>” than “sudo apt-get install <package name>”

First, we need to edit our ~/.bashrc file (~/ signifies your home directory).

sudo gedit ~/.bashrc

Now paste the following lines in the bottom of that file:

alias acs=’apt-cache search’
alias agu=’sudo apt-get update’
alias agg=’sudo apt-get upgrade’
alias agd=’sudo apt-get dist-upgrade’
alias agi=’sudo apt-get install’
alias agr=’sudo apt-get remove’
alias agc=’sudo apt-get clean’
alias aga=’sudo apt-get autoremove’

Save the file. To apply the settings, run “source ~/.bashrc” in a terminal. (Thanks to Endpoint for this tip.)

Now once the settings are applied, you can just follow the model I mentioned in the beginning of this post for installing, removing, etc. packages.

Tip suggested by Alex from The Spinning Cortex

If you eventually want to create more aliases and want to store them all in a separate file, you can create a file called .bash_aliases in your home directory:

gksudo gedit ~/.bash_aliases

You now must enable this file in your ~/.bashrc:

gksudo gedit ~/.bashrc

Now find the lines that look like this:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

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

Uncomment the bottom three, so that they look like this:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

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

Now you can restart the X server and your aliases will be stored in ~/.bash_aliases instead of ~/.bashrc. This is useful if you have a lot of aliases and don’t want to continually mess with ~/.bashrc since it’s an important file.

3 Responses to “apt-get shortcut commands in ubuntu”

  1. alex Says:

    You might prefer to have a separate file for aliases, .bash_aliases. I have this in my .bashrc file (the code might’ve been commented out by default, I can’t remember):

    # Alias definitions.
    # You may want to put all your additions into a separate file like
    # ~/.bash_aliases, instead of adding them here directly.
    # See /usr/share/doc/bash-doc/examples in the bash-doc package.

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

    My favorite alias so far has been
    alias o=’gnome-open $1′
    which emulates the “open” command from OS X. This obviously only works in Gnome.

  2. Erik Söderström Says:

    Why go through the hazzla of restarting X?

    Just do the following:
    1: Open up a terminal
    2: Type source ~/.bashrc (or ~/.bash_aliases if you followed the last tip).

    Tada! It works, and you didn’t have to restart X!

  3. Creare scorciatoie per i comandi di apt-get in ubuntu « Osare Perdere Says:

    [...] Creare scorciatoie per i comandi di apt-get in ubuntu Archiviato in: apt-get, shortcut, linux, Ubuntu — ildiscepolo @ 5:33 pm Ho trovato questo post molto interessante: http://strabes.wordpress.com/2007/01/16/apt-get-shortcut-commands-in-ubuntu/ [...]

Leave a Reply