Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: Combine 4 most useful Apt-Get commands into one!

  1. #1
    Join Date
    Oct 2007
    Location
    Denton, TX
    Beans
    426
    Distro
    Lubuntu Development Release

    Combine 4 most useful Apt-Get commands into one!

    (EDITED on 10/24/08 )

    i have just made a bash script that allows me to run
    Code:
    apt-get check
    apt-get update
    apt-get dist-upgrade
    apt-get autoclean
    apt-get autoremove
    in one bash script. all i have to do is type
    Code:
    apt5
    into a command prompt and the commands will be run. (it used to be 4 commands until somebody suggested i also add "apt-get check". now its 5.

    heres how I did it:

    WARNING: this will update every package on your computer including the kernel and xorg. it is possible this could lead to breakages so be careful and read everything in the terminal before agreeing to update.

    1) i created a directory in my home folder called "bash" (~/bash). This is where I want to copy all custom bash scripts into.
    2) I created a file called "updateall" (without quotes) and I put the file into this bash directory. What I wrote into "updateall" is this:
    Code:
    #!/bin/bash
    #script to run several apt-get commands at once!
    
    apt-get check &&
    
    apt-get update &&
    
    apt-get dist-upgrade &&
    
    apt-get autoremove --purge &&
    
    apt-get autoclean
    I saved it. so now we have a file located at ~/bash/updateall

    3) I created a file in my home directory called ".bash_aliases" (without quotes)
    4) Inside this .bash_aliases I wrote this:
    Code:
    alias apt5='sudo sh ~/bash/updateall'
    5) I restarted bash by logging out and re-logging in.

    thats it! now, no matter where I am in my command prompt, I type
    Code:
    apt5
    and my computer will run an apt-get check, apt-get update, apt-get dist-upgrade, apt-get autoclean, and apt-get autoremove.

    This has saved me countless typing and I hope it can help a lot of other people here that use apt-get instead of the normal update-manager to install updates.

    enjoy!
    Last edited by Saint Angeles; November 1st, 2008 at 08:17 AM. Reason: added another apt-get command so now its actually 5 commands instead of 4.

  2. #2
    Join Date
    Aug 2007
    Location
    La Plata
    Beans
    111
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Combine 4 most useful Apt-Get commands into one!

    Nice! I would append '&&' between commands, so that the next one is only executed if the preceding one succeeds.
    Let's say your internet connection is down, then the first command fails and then it executes the second one that also needs a connection, and it will obviously fail too.
    It's a minor thing, but it makes your otherwise pretty neat script more elegant.

  3. #3
    Join Date
    Oct 2005
    Location
    The Netherlands
    Beans
    105
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Combine 4 most useful Apt-Get commands into one!

    Quote Originally Posted by brunovecchi View Post
    Nice! I would append '&&' between commands, so that the next one is only executed if the preceding one succeeds.
    Let's say your internet connection is down, then the first command fails and then it executes the second one that also needs a connection, and it will obviously fail too.
    It's a minor thing, but it makes your otherwise pretty neat script more elegant.
    additionally, this commando:
    Code:
    sudo apt-get clean
    Will delete the local cache of packages downloaded via synaptic or other methods.

    note that you can also configure this in synaptic. Settings -> Preferences -> Files
    Registered Linux User #413677

  4. #4
    Join Date
    Aug 2008
    Location
    Mordhaus
    Beans
    245
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Combine 4 most useful Apt-Get commands into one!

    Could you explain what each of those commands do?
    <- terminal noob
    NEVER under ANY CIRCUMSTANCES use the commands: sudo rm -rf or rm -rf unless you know EXACTLY what you are doing! These commands will permanently erase data on your computer!

    Guitarists! Show us what you can do!

  5. #5
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: Combine 4 most useful Apt-Get commands into one!

    i just use alias's

    Code:
    alias s='apt-cache search'
    alias i='sudo apt-get install'
    alias r='sudo apt-get --purge remove'
    alias upd='sudo apt-get update;sudo apt-get dist-upgrade;sudo apt-get clean;sudo orphaner'
    example:

    s editor = search editor
    i geany = installs geany
    r geany = removes
    upd = updates and shows upgrades, then cleans


    yours:
    alias all4='sudo apt-get update;sudo apt-get dist-upgrade;sudo apt-get autoclean;sudo apt-get autoremove'
    Last edited by kerry_s; October 23rd, 2008 at 02:49 PM.

  6. #6
    Join Date
    Aug 2008
    Location
    127.0.0.1
    Beans
    91
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Combine 4 most useful Apt-Get commands into one!

    Expanding on this, taking updating out of the equation for the time being, I feel that a script to keep the packages in good order would be useful. I will share mine as follows:

    Code:
    #!/bin/bash
    # keep that package list nice and healthy
    # script to check nothing is broken and clean out all the fluff
    # www.stevey.eu
    
    apt-get check &&
    
    apt-get autoremove &&
    
    apt-get autoclean &&
    
    apt-get clean
    This way we are ensuring everything is in good working order and there is nothing left behind to cause possible issues prior to any attempts at syncing package lists or updating anything on our systems, far safer.

    For those not savvy with the terminal and apt-get commands:

    check will check that you have got no broken packages/dependancies

    autoremove will remove any packages left behind that were installed previously by something else and are no longer required

    autoclean will erase any old archive files used from previous installations of packages

    clean as above but the more recent ones
    Internets //<http://www.stevey.eu>
    Advice given with no warranty implied. Results are the users own responsibility.
    Paragraphs, spelling, and grammar. All very useful, please use them. It makes reading much easier.
    Disable the PC Speaker!

  7. #7
    Join Date
    Aug 2008
    Location
    127.0.0.1
    Beans
    91
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Combine 4 most useful Apt-Get commands into one!

    Quote Originally Posted by kerry_s View Post
    i just use alias's

    Code:
    alias s='apt-cache search'
    alias i='sudo apt-get install'
    alias r='sudo apt-get --purge remove'
    alias upd='sudo apt-get update;sudo apt-get dist-upgrade'
    alias old='sudo apt-get clean;sudo orphaner'
    I have never taken the time to try it out, as I usually use a custom filter within synaptic, but I am presuming orphaner is part of deborphan?

    Does it just work automagically without any prompts removing all the orphaned packages?
    Internets //<http://www.stevey.eu>
    Advice given with no warranty implied. Results are the users own responsibility.
    Paragraphs, spelling, and grammar. All very useful, please use them. It makes reading much easier.
    Disable the PC Speaker!

  8. #8
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: Combine 4 most useful Apt-Get commands into one!

    Quote Originally Posted by steveydoteu View Post
    I have never taken the time to try it out, as I usually use a custom filter within synaptic, but I am presuming orphaner is part of deborphan?

    Does it just work automagically without any prompts removing all the orphaned packages?
    no, everything on mine asks first, you would have to use the " -y, --yes, --assume-yes" if you want that.

    for example, after dist-upgrade, if there's upgrades it stops with the "yes,no" question, then continues.

    ";" makes it only move on after the other is completed.

    yes, orphaner is deborphan, you might want to take that out for ubuntu. i'm using etch.

  9. #9
    Join Date
    Aug 2008
    Location
    127.0.0.1
    Beans
    91
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Combine 4 most useful Apt-Get commands into one!

    Quote Originally Posted by semitone36 View Post
    Could you explain what each of those commands do?
    <- terminal noob
    http://wiki.linuxhelp.net/index.php/Apt-get_Guide
    Internets //<http://www.stevey.eu>
    Advice given with no warranty implied. Results are the users own responsibility.
    Paragraphs, spelling, and grammar. All very useful, please use them. It makes reading much easier.
    Disable the PC Speaker!

  10. #10
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: Combine 4 most useful Apt-Get commands into one!

    Rather the writing a script you can define a function in .bashrc

    update () {
    command1 && command2 && command3 && command4
    }
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •