What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands tagged dpkg from sorted by
Terminal - Commands tagged dpkg - 51 results
apt-show-versions | grep '\bpython\b'
awk '{if ($1 ~ /Package/) p = $2; if ($1 ~ /Installed/) printf("%9d %s\n", $2, p)}' /var/lib/dpkg/status | sort -n | tail
aptitude remove $(dpkg -l|awk '/^ii linux-image-2/{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)}')
2010-12-11 11:38:15
User: __
Functions: awk sed

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

I'm bummed that this took 228 characters. I'd like to see a simpler version.

dpkg -l | grep ^rc | awk '{print $2}' | xargs dpkg -P
dpkg -l | grep ^rc | cut -d' ' -f3 | xargs dpkg -P
dlocate /path/to/file
2010-11-18 19:07:12
User: towo

Works similar to dpkg -S, but uses the locatedb and is thus inarguably a lot faster - if the locatedb is current.

dpkg -L iptables | perl -lne 'print if -f && -x'
find $(dpkg -L iptables) -maxdepth 0 -executable -type f
2010-10-30 15:36:32
User: Juluan
Functions: find

Maybe not clean with big package and too long argument. But return every file who can be executed.

lst=`dpkg -L iptables` ; for f in $lst; do if [ -x $f ] && [ ! -d $f ] ; then echo $f; fi; done;
2010-10-30 14:47:45
User: b_t
Functions: echo

I wanted to view only executables installed by a package. This seemed to work.

There's got to be easier way, please share.


(1) Replace iptables with the package name of your interest

(2) The command will trash any existing environment variable named 'lst'

(3) Instead if you are interested in viewing just .ko or .so files installed by this package, then

that would be easy:

$ dpkg -L iptables | grep "\.[sk]o$"

package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | (while read file; do if [ -f "$file" ];then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file; exit 0; fi; fi; done; exit 1)
2010-09-20 18:10:19
User: pipeliner
Functions: cat echo exit read stat
Tags: apt dpkg date stat

This script compares the modification date of /var/lib/dpkg/info/${package}.list and all the files mentioned there.

It could be wrong on noatime partitions.

Here is non-oneliner:




inst=$(stat "$list" -c %X);

cat $list |


while read file; do

if [ -f "$file" ]; then

acc=$(stat "$file" -c %X);

if [ $inst -lt $acc ]; then

echo used $file

exit 0




exit 1


aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
2010-06-10 21:23:00
User: dbbolton
Functions: awk egrep grep

This should do the same thing and is about 70 chars shorter.

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
2010-06-10 20:33:32
User: mitzip
Functions: sed sudo xargs

This will remove all installed kernels on your debian based install, except the one you're currently using.



dpkg -l | cut -d' ' -f 3 | grep ^python$
aptitude keep-all
2010-04-20 09:24:20
User: dooblem

Very handy if you have done a package selection mistake in aptitude.

Note that it's better to do a Ctrl+U (undo) in aptitude if possible, because the keep-all will clear some package states (like the 'hold' state).

sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn
2009-10-19 19:01:17
User: arcege
Functions: sed sort

Use the hold space to preserve lines until data is needed.

perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less
2009-10-19 12:55:59
User: hfs
Functions: perl sort

List packages and their disk usage in decreasing order. This uses the "Installed-Size" from the package metadata. It may differ from the actual used space, because e.g. data files (think of databases) or log files may take additional space.

cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
2009-09-09 18:09:14
User: kamathln
Functions: cat grep ls readlink rm xargs
Tags: Debian find dpkg

This helped me find a botnet that had made into my system. Of course, this is not a foolproof or guarantied way to find all of them or even most of them. But it helped me find it.

echo -e "${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath /var/lib/dpkg/info/*.list|grep -vxh -f /tmp/allpath >/tmp/installedinpath ; find ${PATH//:/ } |grep -Fxv -f /tmp/installedinpath
2009-09-09 05:33:14
User: kamathln
Functions: echo find grep
Tags: Debian dpkg PATH

OS: Debian based (or those that use dpkg)

Equivalent to doing a dpkg -S on each file in $PATH, but way faster.

May report files generated though postinstall scripts and such. For example . It will report /usr/bin/vim .. which is not not a file installed directly by dpkg, but a link generated by alternatives hooks

dpkg-deb -x $debfile $extractdir; dpkg-deb -e $debfile $extractdir/DEBIAN;
2009-08-07 20:33:43
User: flokra

extracts the debian-package $debfile to $extractdir, including all packaging-information. to repack the package, just type:

dpkg-deb -b $extractdir
dpkg -S `which nm` | cut -d':' -f1 | (read PACKAGE; echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}"; dpkg -L "${PACKAGE}") | less
2009-07-14 20:21:48
User: mohan43u
Functions: cut echo read
Tags: which dpkg

In Debian based distros, this command will list 'binutils' package details which contains 'nm' command. You can replace 'nm' to any other command.

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
2009-06-19 10:23:38
User: plasticdoc
Functions: sed
Tags: Linux sed dpkg

will show:

installed linux headers, image, or modules: /^ii/!d

avoiding current kernel: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d

only application 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
2009-06-19 10:11:00
User: plasticdoc
Functions: sed sudo xargs

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

sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove
2009-04-28 10:34:42
User: kelevra
Functions: awk grep sudo
Tags: awk apt-get dpkg

Useful for removes a package and its depends, for example to remove the gnome desktop environment, also configuration files will be removed, you should be carefully and sure that you want to do this.

dpkg -S /usr/bin/ls
2009-04-18 18:18:23
User: bwoodacre

'dpkg -S' just matches the string you supply it, so just using 'ls' as an argument matches any file from any package that has 'ls' anywhere in the filename. So usually it's a good idea to use an absolute path. You can see in the second example that 12 thousand files that are known to dpkg match the bare string 'ls'.