Use command aliases for lazy terminal installing, purging & searching

This neat little tip was dropped off in our inbox by a reader called Darren – so thanks goes to him.

Become a lazy geek

€œFed up with typing ‘sudo apt-get install blahblah', ‘apt-cache search blahblah' and ‘sudo apt-get purge blahblah'?€œ asks Darren.

Add the following ‘aliases’ to the ‘bashrc’ file in your home folder. You can locate this by pressing CTRL + H when in your home folder and seeking out ‘.bashrc’ (note the period)

alias install=’sudo apt-get -y install’
alias search=’apt-cache search’
alias purge=’sudo apt-get purge’

Now you can use the following simple commands in the terminal, using 'sudo' where applicable.

  • To search for a package: search rhythmbox
  • To install a package: install rhythmbox
  • To purge a package: purge rhythmbox

Related posts:

  1. Automatically Install Missing PPA GPG Keys With One Command (or your money back*)
  2. Online Mencoder Command Generator makes command line DVD conversion a cinch
  3. How To Download YouTube Video’s In Ubuntu Without Addons, apps, terminal etc
Post a comment or leave a trackback: Trackback URL.
  • http://twitter.com/inkubux Francis Belanger

    Nice trick, However I prefer AutoKey to acheive the same. The best thing with AutoKey is that it works for any application

    • https://launchpad.net/~gotunandan gotunandan

      so do bash aliases. They work for GUI applications also, not just CLI tools

      • http://twitter.com/inkubux Francis Belanger

        Yes but Autokey is a text replacement tool so in Gedit you could type an abbreviation like addr and it will replace addr with your actual address. There is infinite possibilities with AutoKey. The good thing is that even in an SSH session your abbreviations will work. You can use it to store Code templates that work across all applications.

  • http://www.expatsinksa.com/ Bilal Akhtar

    MISTAKE: We should add those alias lines to .bashrc file in home folder, otherwise they will get reset when we close the terminal.

    • http://omgubuntu.co.uk/ d0od

      Whoops, added. Nice catch Bilal :D

    • http://claimid.com/el-bhm bhm

      It’s better to keep it in ~/.bash_aliases for clarity.

      BTW, there’s one downside. You can double tap TAB to autocomplete.

  • http://thealphanerd.wordpress.com/ Calvin

    Remember apt-cache show!

  • http://karlicoss.mp/ karlicoss

    Or just use debman:
    search: debman -Ss package
    install: debman -S package
    remove debman -R package
    update&&upgrade: debman -yu
    add PPA repository: debman -A ppa:ppaname
    and so on :)

    • http://dottorblaster.it/ Bl@ster

      A Pacman-like apt CLI frontend? So awesome :D

    • Anonymous

      Is this for Jaunty as well?

  • Anonymous

    I also recommend doing such for upgrading system – alias upgrade=’sudo apt-get update && sudo apt-get upgrade’
    And of course, add all of these aliases into ~/.bashrc

  • http://itbcn8world.spaces.live.com itbcn8

    “… simple commands in the termina, using ‘sudo’ …”

    <– terminal is missing the "l", fyi :)

  • Anonymous

    bad alias, there is an app called install

    • Lazy O>

      And, if I’m not mistaken, it’s what you use to install programs you have just compiled.

      • http://twitter.com/Heimpjuh Heimen Stoffels

        Nope, that’s ‘sudo make install’ which works correctly. I have install as alias for a long time now and never have any problems with compiling programs. sudo make install works correctly.

      • http://twitter.com/Heimpjuh Heimen Stoffels

        Nope, that’s ‘sudo make install’ which works correctly. I have install as alias for a long time now and never have any problems with compiling programs. sudo make install works correctly.

  • Zoff

    I usually set this aliases.
    I suppose names are not user-friendly for all but they are perfect for me as they are.

    alias allrepo=’cat /etc/apt/sources.list `ls /etc/apt/sources.list.d/*.list` | egrep -v “^$”‘
    alias search=’apt-cache search’ #search a package
    alias show=’apt-cache show’ #display package information
    alias repo=’allrepo | egrep -v “^#”‘ #display all active repo
    alias saar=’sudo add-apt-repository’ #add a repo to repo .list
    alias sag=’sudo apt-get’ # simple apt-get shortcut
    alias sagar=’sudo apt-get autoremove’ # autoremove
    alias sagc=’sudo apt-get clean’ #clean package cache
    alias sagi=’sudo apt-get install’ #install a package
    alias sagir=’sudo apt-get install –reinstall’ #reinstall a package
    alias sagp=’sudo apt-get purge’ #purge a package
    alias sagu=’sudo apt-get update’ #update repo’s packages list
    alias sagud=’sudo apt-get dist-upgrade’ #dist-upgrade
    alias sagui=’sagu && sagi’ # update repo & install package (usefull when u just added a repo)
    alias sagup=’sudo apt-get upgrade’ #package upgrade
    alias sagupd=’sagu && sagup -y && sagud’ #global update
    alias ska=’sudo killall’ #kill process by name
    alias sug=’sudo update-grub’ #update grub
    alias sug2=’sudo update-grub2′ #update grub2
    alias suse=’sudo service’ #access a system service

    • Anonymous

      Is this intended to be easier to remember? Or just to save typing? or what? very odd.

      • http://www.google.com/profiles/will.price94 Will

        Why very odd? seems perfectly logical to me.

        • Anonymous

          i reckon they’re harder to remember (and more confusing) than the original commands, and when you *do* get used to them they’ll leave you floundering for man pages on any other system where they’re not in effect. All to save a really minimal number of keystrokes.

          Ah well, to each his own, I suppose :)

  • http://twitter.com/whatnotery John O’shea

    My alias for sudo apt-get install is canhas

    • Eugeny

      ~/.canhaz: sudo apt-get install $3~/.bashrc: alias i=’~/.canhaz’~$ i can haz cheese burger
      (installs Cheese)

  • EXIT31

    Where in the file need i put these lines?

    • http://claimid.com/el-bhm bhm

      Anywhere you like.

  • lala

    I’m sort of reluctant to put anything that uses sudo into aliases. I rather put scripts into /usr/local/bin . You write a script with your favourite text editor, save it and do: “chmod +x name_of_script_file”. Then just
    “sudo cp name_of_script_file /usr/local/bin/” .
    Here’s my package search script (called “pkg-srch”) – copy without the = :

    ================================================================

    #!/bin/bash
    apt-cache search $1 | sort | less

    ===================================================================

    This searches packages, sorts them alphabetically and uses less to view it. You can navigate the output py using the up and down arrow keys. With large output, just press the “/” button and type a search string. It will mark any occasion of the searched term occurring. Type “/” + up arrow + enter to jump to the next line where the word occurs.

    To see if a package is installed, I use this script (“pkg-state”):

    ============================================================

    #!/bin/bash
    echo “” && echo “Package $1 is” && aptitude show $1 | grep State | cut -c 8- && echo “”

    ==================================================================

    It says “Package foo is… installed / not installed”.

  • Anonymous

    You should be putting these into ~/.bash_aliases

    For what its worth, I’d also add :
    alias aliases=’gedit ~/.bash_aliases’

    Makes it simpler/ more convenient to add/edit/remove your aliases.

  • Anonymous

    sg – sudo gedit

    • https://launchpad.net/~navneethc Navneeth

      It is usually recommended to use gksu or gksudo, instead of sudo, when using apps with GUI.

      See here, for instance: http://www.psychocats.net/ubuntu/graphicalsudo

      • Anonymous

        sudo is fine for gedit, gksudo is annoying with it’s popup password screen

  • Anonymous

    Aaauggh… that’s hot. Using minor scripting to become lazier, who’d have thunk it? Bringing up a package manager seems outright stupid, now, since I know all the programs I’d like. I assume this works with multiple package entries.

  • Eugeny

    Aliasing ‘install’ is a *very* bad idea if you are ever going to compile software and build debs

    • http://twitter.com/Heimpjuh Heimen Stoffels

      No problems here with compiling after using install as an alias for a long time. What exactly could be the problem? sudo make install works correctly in compiling.

      • Eugeny

        AFAIK, checkinstall uses install(1) command to build file structure in
        separate folder and then pack these into deb

        2010/9/8 Disqus

  • ninjapirate89

    This is the best post you guys have had in a while, thanks! :D

  • ninjapirate89

    I keep getting ‘command not found’ :(

  • Anonymous

    Yeah, I agree with this. If the contents of this post is in any way news to you, then just use CLIcompanion instead. Poorly constructed aliases (such as ‘install’, as has been pointed out) will bite you on the arse sooner or later, when you spend ages trying to work out why something’s not working.

    (quick example: if you alias over ‘install’ it may (almost certainly will) break many scripts which you had no idea were using ‘install’ – and it’ll take you forever to work out what the problem was)

  • http://www.google.com/profiles/will.price94 Will

    you think ‘install’ is lazy!? i use ‘get’ install takes too long to type…

  • Anonymous

    Man, I’m really not sure about this. It’s really easy to break stuff doing this, and the gains in this case are minimal at best. There are loads of good, incredibly useful bash tips out there[*], but over-use of aliasing without a decent grasp of bash scripting is just asking for trouble.

    as is mentioned below, if you alias over ‘install’ it will break many scripts which you had no idea were using ‘install’ – and you’ll spend ages work out what the problem was. your system will respond differently to the script from everyone else’s, and no-one will be able to replicate your problem, or debug it for you. there are countless other mistakes that can be made too.

    sorry to be negative.

    * to add something constructive, here’s a really fantastic one (and a surprisingly little-known one, even amongst bash geeks). Create a file in your home folder called “.inputrc”, and add this:

    =========
    “eOA”: history-search-backward
    “e[A”: history-search-backward
    “eOB”: history-search-forward
    “e[B”: history-search-forward
    “eOC”: forward-char
    “e[C”: forward-char
    “eOD”: backward-char
    “e[D”: backward-char
    =========

    then restart bash (close your terminal emulator and reopen it, or just type `reset`, or some other way), and then begin typing a command. then press your ‘up’ key, to cycle through commands in your .bash_history which begin in the same way as your unfinished command. It’s seriously useful, and it’s ‘newbie-proof’ (if that doesn’t come across too patronising).

  • Anonymous

    If it’s all about being lazy, you could add apt-get to the sudoers file to save you typing you’re password.
    If you want to do that, make sure you use “sudo visudo” to edit it and add the following line to the bottom of the file:

    ALL= NOPASSWD: /usr/bin/apt-get

    Replacing “” by whatever you’re user name is (incidentally, you’ll be the only one that can run the command without the root password… But you probably don’t want to give everyone permission to do so).

    Using “visudo” means that you’ll have to know how to use vim. In this case it’s just a matter of scrolling to the bottom of the page (“G”) entering insert mode (by pressing “i”), typing the line, pressing ESC and then typing “:wq”.

    That being said, “install” isn’t a very good alias; it’s long and there’s already a command called “install”. May as well just call it “i”…

  • Anonymous

    If it’s all about being lazy, you could add apt-get to the sudoers file to save you typing you’re password.
    If you want to do that, make sure you use “sudo visudo” to edit it and add the following line to the bottom of the file:

    ALL= NOPASSWD: /usr/bin/apt-get

    Replacing “” by whatever you’re user name is (incidentally, you’ll be the only one that can run the command without the root password… But you probably don’t want to give everyone permission to do so).

    Using “visudo” means that you’ll have to know how to use vim. In this case it’s just a matter of scrolling to the bottom of the page (“G”) entering insert mode (by pressing “i”), typing the line, pressing ESC and then typing “:wq”.

    That being said, “install” isn’t a very good alias; it’s long and there’s already a command called “install”. May as well just call it “i”…

  • http://twitter.com/Nickbaskerville Nick Baskerville

    These are really helpful, just made a load of them for my folders that i need to cd to regularly

  • http://ubuntudroid.blogspot.com ubuntudroid

    Hm, maybe I’m entirely wrong, but I thought users were advised to use aptitude instead of apt-get some iterations ago…

    • Anonymous

      actually aptitude has been bumped, and will no longer even be installed by default from Maverick onwards.

      • http://ubuntudroid.blogspot.com ubuntudroid

        Oh, good to know! Seems I have to change to apt-get as well ;) Thanks, mates!

        • Anonymous

          well, you don’t *have* to – you can always:

          sudo apt-get install aptitude

          ;)

          • http://ubuntudroid.blogspot.com ubuntudroid

            Yeah, but they have good reasons to make available only apt-get by default like Dr P Fenderson statet. So: It’s time for a change^^

  • http://insight.pinkonbrown.org Dr P Fenderson

    Here’s a couple I use frequently – I find the upgrate one gets used a whole lot…as well as the repo one.

    alias upgrate=’sudo apt-get update && sudo apt-get upgrade’
    alias dupgrate=’sudo apt-get update && sudo apt-get dist-upgrade’
    alias apti=’sudo apt-get install’
    alias remove=’sudo apt-get remove’
    alias purge=’sudo apt-get purge’
    alias asearch=’sudo apt-cache search’
    alias repo=’sudo apt-add-repository’
    alias sgedit=’sudo gedit’
    alias update=’sudo apt-get update’
    alias upgrade=’sudo apt-get upgrade’
    alias die=’sudo killall’

  • http://anxiousnut.wordprss.com Anxious Nut

    d0od, you didnt mention that one has to reload bashrc!! Now reader are restarting their PCs because of that! Just add this command: source ~/.bashrc

  • Turboneno

    To use less keystrokes and having some aliases that won’t break anything, I use those:
    alias ins=’sudo apt-get -y install’
    alias up=’sudo apt-get update && sudo apt-get upgrade’
    alias rem=’sudo apt-get autoremove –purge’

    There are no ins, up or rem commands, AFAIK.

  • Anonymous

    yeap! I got so fedup … I wrote a short script to do that! Thanks for sharing!

  • http://twitter.com/mshenrick Mark Henrick

    bash: alias: apt-get: not found
    bash: alias: -y: not found
    bash: alias: install’: not found

    weird i know

    • Anonymous

      you’ve used backticks (`) (or typographic quotes) instead of straight single quotes (‘) – blame the OMG/Disqus “smart-quoting” (which will probably break mine too) ;) and be careful! aliasing sudo and backticks is a scary combination… [hides behind sofa in horror!]@OMG guys – don’t know how Disqus works, but could you look into allowing code tags in comments? actually – using code tags which disable “smart”-quoting in your posts would be pretty handy!

    • http://twitter.com/itsdarklikehell bauke molenaar

      its because the ‘ s are not good..

      alias install=’sudo apt-get -y install’
      alias search=’apt-cache search’
      alias purge=’sudo apt-get purge’

      has to be:

      alias install=’sudo apt-get -y install’
      alias search=’apt-cache search’
      alias purge=’sudo apt-get purge’

  • Pingback: What are the dangers with using "–assume-yes" with apt-get? | MoVn - Linux Ubuntu Center

  • Pingback: What are the dangers with using “–assume-yes” with apt-get? | Q&A System