Extract list of packages installed on one server and generate 'apt' command to install them on a new server

dpkg --list | rgrep ii | cut -d" " -f3 | sed ':a;N;$!ba;s/\n/ /g' | sed 's/^\(.\)/apt-get install \1/'
No params
Sample Output
apt-get install acl adduser anthy-common apt apt-utils aptitude authbind avahi-daemon base-files base-passwd bash bind9-host binutils bsdmainutils bsdutils busybox bzip2 ca-certificates ca-certificates-java collectd collectd-core coreutils cpio cpp cpp-4.4 cron curl dash dbus debconf debconf-i18n debian-archive-keyring debianutils deborphan defoma dhcpcd dialog diffutils dmidecode dmsetup dnsutils dpkg dstat e2fslibs e2fsprogs emacs emacs23 emacs23-bin-common emacs23-common emacsen-common fancontrol file findutils firmware-linux-free fontconfig fontconfig-config fping gcc gcc-4.4 gcc-4.4-base gconf2-common geoip-database gettext-base gnupg gpgv grep groff-base grub grub-common grub-pc gsfonts gsfonts-x11 gzip hicolor-icon-theme hostname htop ifupdown info initramfs-tools initscripts insserv install-info iproute iptables iputils-ping java-common joe klibc-utils less lftp libaccess-bridge-java libaccess-bridge-java-jni libacl1 libanthy0 libasound2 libasyncns0 libatk1.0-0 libatk1.0-data libattr1 libavahi-client3 libavahi-common-data libavahi-common3 libavahi-core7 libbind9-60 libblkid1 libboost-iostreams1.42.0 libbsd0 libbz2-1.0 libc-bin libc-dev-bin libc6 libc6-dev libcairo2 libcap-ng0 libcap2 libcomerr2 libcommons-collections3-java libcommons-dbcp-java libcommons-pool-java libcroco3 libcups2 libcurl3 libcurl3-gnutls libcurses-perl libcurses-ui-perl libcwidget3 libdaemon0 libdatrie1 libdb4.7 libdb4.8 libdbi0 libdbi1 libdbus-1-3 libdbus-glib-1-2 libdevmapper1.02.1 libdns69 libecj-java libedit2 libept1 libesmtp6 libevtlog0 libexpat1 libflac8 libfont-freetype-perl libfontconfig1 libfontenc1 libfreetype6 libfribidi0 libgcc1 libgconf2-4 libgcrypt11 libgd2-noxpm libgdbm3 libgeoip1 libgif4 libglib2.0-0 libglib2.0-data libgmp3c2 libgnutls26 libgomp1 libgpg-error0 libgpm2 libgsf-1-114 libgsf-1-common libgssapi-krb5-2 libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libhal1 libice-dev libice6 libidl0 libidn11 libisc62 libisccc60 libisccfg62 libjasper1 libjpeg62 libk5crypto3 libkeyutils1 libklibc libkrb5-3 libkrb5support0 liblcms1 libldap-2.4-2 liblocale-gettext-perl liblockfile1 libltdl7 liblua5.1-0 liblwres60 liblzma2 libm17n-0 libmagic1 libmemcached10 libmodbus5 libmpfr4 libmysqlclient16 libncurses5 libncursesw5 libnet-snmp-perl libnet1 libnewt0.52 libnfnetlink0 libnl1 libnspr4-0d libnss-mdns

By: pablor44
2012-10-16 07:51:18

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

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

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: