Commands tagged apt-get (29)

  • (also works on Ubuntu) Copies the 'install,' 'hold,' 'deinstall' and 'purge' states of packages on the remote machine to be matched on the local machine. Note: if packages were installed on the local machine that were never installed on the remote machine, they will not be deinstalled by this operation.

    ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install
    Mozai · 2011-05-12 17:26:43 0
  • Limits the usage of bandwidth by apt-get, in the example the command will use 30Kb/s ;) It should work for most apt-get actions (install, update, upgrade, dist-upgrade, etc.)

    sudo apt-get -o Acquire::http::Dl-Limit=30 upgrade
    alemani · 2010-03-22 01:29:44 1

  • 12
    apt-get install `ssh root@host_you_want_to_clone "dpkg -l | grep ii" | awk '{print $2}'`
    TuxOtaku · 2011-05-10 13:33:51 3
  • will purge: only installed apps: /^ii/!d avoiding current kernel stuff: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d using app names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/ avoiding stuff without a version number: /[0-9]/!d

    dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
    plasticdoc · 2009-06-19 10:11:00 0
  • apt-get is pretty aggressive when it downloads, potentially hogging the bandwidth of your network. The 25 is in KB, change this to your needs.

    sudo apt-get -o Acquire::http::Dl-Limit=25 install <package>
    dunnix · 2009-07-31 19:43:45 2

  • 4
    apt-cache stats
    0disse0 · 2009-09-03 19:29:17 0
  • This will remove all installed kernels on your debian based install, except the one you're currently using. From:

    dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
    mitzip · 2010-06-10 20:33:32 0
  • You need to install "sshpass" for this to work. apt-get install sshpass

    sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
    o0110o · 2013-05-24 14:33:38 3

  • 3
    apt-get --just-print upgrade
    noqqe · 2010-02-18 11:19:05 5
  • This let's you find out the total packages that have available upgrades. Usefull if you want to check or show the total available upgrades on your system. Show Sample Output

    apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1 " package updates are available"}'
    lpanebr · 2012-03-29 17:04:32 0
  • Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.

    sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic*//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
    mtron · 2012-08-15 10:02:12 1
  • Change the APP variable's value to whatever you want to install. Depending on how fast your machine is, you'll want to adjust the value 50 to something else. You might also want to play a different game than Gnometris - just make sure it's a GUI game.

    APP=wine; if [ $(sudo apt-get --print-uris -y install $APP | sed -ne 's/^After this operation, \([0-9]\{1,\}\).*MB.*/\1/p') -gt 50 ]; then gnometris 2>/dev/null & sudo apt-get install $APP; else sudo apt-get install $APP; fi
    rkulla · 2010-04-18 19:32:26 0
  • in Debian-based systems apt-get could be limited to the specified bandwidth in kilobytes using the apt configuration options(man 5 apt.conf, man apt-get). I'd quote man 5 apt.conf: "The used bandwidth can be limited with Acquire::http::Dl-Limit which accepts integer values in kilobyte. The default value is 0 which deactivates the limit and tries uses as much as possible of the bandwidth..." "HTTPS URIs. Cache-control, Timeout, AllowRedirect, Dl-Limit and proxy options are the same as for http..."

    sudo apt-get -o Acquire::http::Dl-Limit=20 -o Acquire::https::Dl-Limit=20 upgrade -y
    ruslan · 2011-02-14 05:24:49 0

  • 2
    sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
    funkjedi · 2015-03-15 15:57:19 1
  • Running 'cpan Module::Name' will install that module from CPAN. This is a simple way of using a similar command to install a packaged Perl module from a Debian archive using apt-get. Show Sample Output

    function dpan () { PKG=`perl -e '$_=lc($ARGV[0]); s/::/-/g; print "lib$_-perl\n"' $1`; apt-get install $PKG; }
    dave0 · 2009-03-12 15:39:38 1
  • You can't stand programs x, y, and z. Remove all trace of their existence by adding this function to your config. It will remove the cruft, the settings, and such and such. This function doesn't even give a damn about you trying to remove programs that don't exist: it'll just for loop to the next one on your hit list. Show Sample Output

    function nuke() { if [ $(whoami) != "root" ] ; then for x in $@; do sudo apt-get autoremove --purge $x; done; else for x in $@; do apt-get autoremove --purge $x; done; fi }
    ruinbox · 2009-03-25 23:21:21 2
  • Trickle is here: Trickle is a simple bandwidth limiter

    trickle sudo apt-get update -y
    mrman · 2011-02-15 02:05:37 0
  • Usefull if you only want to see the package names, or if you want to use them in a script.

    apt-get -s upgrade | awk '/Inst.+/ {print $2}'
    lpanebr · 2013-03-25 21:23:11 0
  • If, for example, you want to remove all kernels and headers but the last three versions, you can't use one of that magic all-in-one "remove old stuff" commands. With this simple but elegant command you can remove a range of versions, or a list of versions with e.g. {14,16,20}. Show Sample Output

    apt purge linux*{14..18}*
    ppq · 2016-04-20 07:44:55 0
  • on a dpkg managed system this PATTERN will help you generate .deb files from source AND remove all the dev libs you had to install. i hate cluttering up my machine with rouge packages and headers. it would be pretty darn easy on rpm systems as well. i just dont have a rpm managed system to test on right now. NOTE, you sharp ones will notice that it uninstalls the deb you just made! yeah, but the deb is still there to do with it what you want, like re install it. or you can just grep -v after the diff

    dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge
    danlangford · 2010-06-16 22:06:07 1
  • This alias is quicker to type than 'sudo apt-get install', and it automatically says yes to the prompt that shows up sometimes.

    alias sagi="yes | sudo apt-get install"
    theepicsnail · 2011-03-06 03:45:47 1
  • This will extract all the apt-get install commands issued on the box, even if they are in the gzipped history files. Show Sample Output

    zgrep --color=always 'get install' /var/log/apt/history.log*
    saherr1969 · 2012-04-18 00:06:14 0
  • Install all build dependencies for a given package Show Sample Output

    sudo apt-get build-dep rhythmbox
    darlanalves · 2013-10-07 23:13:19 0
  • # AllInOne: Update what packages are available, upgrade to new versions, remove unneeded packages # (some are no longer needed, replaced by the ones from ap upgrade), check for dependencies # and clean local cached packages (saved on disk but not installed?,some are needed? [this only cleans unneeded unlike ap clean]). # aliases (copy into ~/.bashrc file): alias a='alias' a ap='apt-get' a r='ap autoremove -y' a up='ap update' a u='up && ap upgrade -y --show-progress && r && ap check && ap autoclean' # && means "and run if the previous succeeded", you can change it to ; to "run even if previous failed". I'm not sure if ap check should be before or after ap upgrade -y, you can also change the alias names. # To expand aliases in bash use ctrl alt e or see this # For more useful aliases go to

    apt-get update && apt-get dist-upgrade -y --show-progress && apt-get autoremove -y && apt-get check && apt-get autoclean -y
    unixmonkey78577 · 2014-07-26 12:18:57 0
  • Works for Debian an sons distros. With a bad internet connection sometime I download the updateable packages in another place, but I can't be there all time takes upgrade every packages... so I execute this for update only packages that are in Debian's apt cache. Using the 'sudo bash -c' for no asking every time apt-get need sudo permition.

    sudo bash -c "apt-get upgrade -s |grep 'Inst '| cut -d' ' -f2| xargs -l1 apt-get install - --no-download"
    DellDor · 2015-08-10 01:48:08 0
  •  1 2 > 

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Convert a single-page PDF to a hi-res PNG, at 300dpi
If you skip this part: $ -density 300x300 you'll get a very lo-res image.

Find files of two different extensions and copy them to a directory

Listing today’s files only

Determining the excat memory usages by certain PID
this command gives you the total number of memory usuage and open files by the perticuler PID.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Create a directory and go inside it
$_ expands to the last argument of the last command that was executed

list block devices
Shows all block devices in a tree with descruptions of what they are.

How to copy CD/DVD into hard disk (.iso)
A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command

Watch the progress of 'dd'
run this in another terminal, were xxxx is the process ID of the running dd process. the progress will report on the original terminal that you ran dd on

Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output)
Excludes other mountpoints with acavagni's "mountpoint" idea, but with -exec instead of piping to an xargs subshell. Then, calling "du" only once with -exec's "+" option. The first "\! -exec" acts as a test so only those who match are passed to the second "-exec" for du.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: