Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

(Debian/Ubuntu) Discover what package a file belongs to

Terminal - (Debian/Ubuntu) Discover what package a file belongs to
dpkg -S /usr/bin/ls
2009-04-18 18:18:23
User: bwoodacre
39
(Debian/Ubuntu) Discover what package a file belongs to

'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'.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
dlocate /path/to/file
2010-11-18 19:07:12
User: towo
7

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

pacof -e rlogin
2011-11-04 13:17:04
User: pipeliner
-2

Uses dpkg -S or apt-file to find the file you want and shows results in various ways. Available at https://github.com/Pipeliner/configs/blob/master/bin/pacof

pacof -xp 'bin/[^/]*mixer'

alsamixergui

alsa-tools-gui

alsa-utils

...

Know a better way?

If you can do better, submit your command here.

What others think

oh yes, so sweet and tasty!

Comment by linuxrawkstar 292 weeks and 5 days ago

If you need regex,

apt-file -x search /some/file
Comment by stu 292 weeks and 5 days ago

apparently dlocate is much faster for this if you find yourself needing to do a lot of sleuthing.

Comment by bwoodacre 292 weeks and 4 days ago

Thanks for this :)

Comment by stormerider 292 weeks and 2 days ago

This will do the opposite, what files a package generated during installation.

dpkg -L packagename
Comment by alperyilmaz 292 weeks ago

I wish I could vote this up again! what a time saver.

Comment by linuxrawkstar 291 weeks and 3 days ago

The above are for apt based systems. For portage on gentoo, you need the app-portage/gentoolkit package installed and do

equery belongs /some/file
Comment by paulkoan 291 weeks and 1 day ago

I used grep to filter, and that additionally gives

(A) all symbolic link (with the same name) installed by the package as well,

(B) other files/directories with the same name installed by other packages.

if that info is of any use to you.

Example and output will make it more clear:

Example:

dpkg -S ip | grep "/ip$"

Output:

linux-headers-2.6.27-7-generic: /usr/src/linux-headers-2.6.27-7-generic/include/config/ip

iproute: /bin/ip

iproute: /sbin/ip

First line of the output is a directory by name ls intalled

by the package linux-headers-2.xxxx

Second line is the executable by name ip

The last line of the output is the symbolic link to

the command ip

You need to replace both instances of string ip with the command/file of your interest in my example command.

Comment by b_t 212 weeks and 6 days ago

Typo: First line of the output is a directory by name ls intalled

Read: First line of the output is a directory by name 'ip' installed

Comment by b_t 212 weeks and 6 days ago

You might want:

dpkg -S `which ls`

You might know the command but not the full path, i.e. on Ubuntu 11.10:

which ls

/bin/ls

So your command would't actually tell you what package ls comes from on this distro.

Comment by andrewsomething 160 weeks and 4 days ago

in the redhat world this is similar to rpm -qf fllename.

I just learned this for debian based systems today. It's useful.

Comment by sonic 92 weeks and 4 days ago

A page with all common package managers commands:

http://wiki.openvz.org/Package_managers

Comment by kernel01 67 weeks and 3 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts