Commands tagged apt-get (30)

  • (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.


    27
    ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install
    Mozai · 2011-05-12 17:26:43 11
  • 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.)


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

  • 13
    apt-get install `ssh root@host_you_want_to_clone "dpkg -l | grep ii" | awk '{print $2}'`
    BoxingOctopus · 2011-05-10 13:33:51 7
  • 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


    7
    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 9
  • 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.


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

  • 4
    apt-cache stats
    0disse0 · 2009-09-03 19:29:17 3
  • This will remove all installed kernels on your debian based install, except the one you're currently using. From: http://tuxtweaks.com/2009/12/remove-old-kernels-in-ubuntu/comment-page-1/#comment-1590


    4
    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 5
  • You need to install "sshpass" for this to work. apt-get install sshpass


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

  • 3
    apt-get --just-print upgrade
    noqqe · 2010-02-18 11:19:05 8
  • 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


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


    3
    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 6
  • 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.


    2
    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 39
  • 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..."


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

  • 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 9
  • 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


    1
    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 13
  • 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


    1
    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 8
  • Trickle is here: http://monkey.org/~marius/pages/?page=trickle Trickle is a simple bandwidth limiter


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


    1
    apt-get -s upgrade | awk '/Inst.+/ {print $2}'
    lpanebr · 2013-03-25 21:23:11 4
  • 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


    1
    apt purge linux*{14..18}*
    ppq · 2016-04-20 07:44:55 11
  • 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


    0
    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 4
  • This alias is quicker to type than 'sudo apt-get install', and it automatically says yes to the prompt that shows up sometimes.


    0
    alias sagi="yes | sudo apt-get install"
    theepicsnail · 2011-03-06 03:45:47 5
  • 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


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


    0
    sudo apt-get build-dep rhythmbox
    darlanalves · 2013-10-07 23:13:19 6
  • # 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 ow.ly/zBKHs # For more useful aliases go to ow.ly/zBMOx


    0
    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 6
  • 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.


    0
    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 9
  •  1 2 > 

What's this?

commandlinefu.com 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

Sort lines using the Xth characted as the start of the sort string
Tells sort to ignore all characters before the Xth position in the first field per line. If you have a list of items one per line and want to ignore the first two characters for sorting purposes, you would type "sort -k1.3". Change the "1" to change the field being sorted. The decimal value is the offset in the specified field to sort by.

Extract title from HTML files
This command can be used to extract the title defined in HTML pages

Install pip with Proxy
Installs pip packages defining a proxy

Bash prompt with user name, host, history number, current dir and just a touch of color
I put that line in my .bash_profile (OS X) and .bashrc (Linux). Here is a summary of what the \char means: n=new line, u=user name, h=host, !=history number, w=current work directory The \[\e[32m\] sequence set the text to bright green and \[\e[0m\] returns to normal color. For more information on what you can set in your bash prompt, google 'bash prompt'

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Create a file of a given size in linux
If you're trying to create a sparse file, you can use dd by 'skip'ing to the last block instance. ls -ls shows the actual size vs. the reported size

Command line calculator
This opens a python command line. You can use math and random and float-division is enabled (without appending .0 to integers). I just don't know how to specify a standard precision.

Make vim open in tabs by default (save to .profile)
I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs.

Monitoring file handles used by a particular process
-r : repeat mode

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: