Difference between revisions of "Pkgfile"

From ArchWiki
Jump to: navigation, search
m (Example:: add italics for repo names)
("Command not found" hook: moved info from "command not found hook" section from https://wiki.archlinux.org/index.php?title=Zsh)
Line 33: Line 33:
 
=== "Command not found" hook ===
 
=== "Command not found" hook ===
  
pkgfile includes a "command not found" hook that will automatically search the official repositories, if you enter an unrecognized command.
+
pkgfile includes a "command not found" hook that will automatically search the official repositories, if you enter an unrecognized command. Then it will display something like this:
 +
 
 +
{{hc|$ abiword|
 +
abiword may be found in the following packages:
 +
  extra/abiword 2.8.6-7 usr/bin/abiword
 +
}}
  
 
To enable it in all children shells, you need to source the hook from one of your shell initialization files.
 
To enable it in all children shells, you need to source the hook from one of your shell initialization files.
Line 46: Line 51:
 
{{hc|~/.zshrc|
 
{{hc|~/.zshrc|
 
source /usr/share/doc/pkgfile/command-not-found.zsh}}
 
source /usr/share/doc/pkgfile/command-not-found.zsh}}
 +
 +
An alternative "command not found" hook is also provided by the AUR package {{AUR|command-not-found}}, which will generate an output like the following:
 +
 +
{{hc|$ abiword|
 +
The command 'abiword' is been provided by the following packages:
 +
'''abiword''' (2.8.6-7) from extra
 +
[ abiword ]
 +
'''abiword''' (2.8.6-7) from staging
 +
[ abiword ]
 +
'''abiword''' (2.8.6-7) from testing
 +
[ abiword ]
 +
}}
 +
 +
for it to work, add the following to a zshrc:
 +
 +
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh
  
 
==See also==
 
==See also==
 
* [[Bash#The_"command_not_found"_hook]] - Section comparing {{Pkg|pkgfile}} and {{AUR|command-not-found}}
 
* [[Bash#The_"command_not_found"_hook]] - Section comparing {{Pkg|pkgfile}} and {{AUR|command-not-found}}

Revision as of 19:41, 21 February 2014

pkgfile is a tool that tells you which package owns a specified file or which files a given package provides.

You can install pkgfile from the official repositories, or pkgfile-gitAUR from the AUR.

Then update the file database:

# pkgfile --update

Example:

Example to search for a package that contains a file named "makepkg":

$ pkgfile makepkg
core/pacman

So your searched file is in the pacman package from the [core] repository.

Another example to list all files provided by the archlinux-keyring package from the [core] repository:

$ pkgfile --list core/archlinux-keyring
core/archlinux-keyring usr/
core/archlinux-keyring usr/share/
core/archlinux-keyring usr/share/pacman/
core/archlinux-keyring usr/share/pacman/keyrings/
core/archlinux-keyring usr/share/pacman/keyrings/archlinux-revoked
core/archlinux-keyring usr/share/pacman/keyrings/archlinux-trusted
core/archlinux-keyring usr/share/pacman/keyrings/archlinux.gpg

"Command not found" hook

pkgfile includes a "command not found" hook that will automatically search the official repositories, if you enter an unrecognized command. Then it will display something like this:

$ abiword
abiword may be found in the following packages:
  extra/abiword 2.8.6-7	usr/bin/abiword

To enable it in all children shells, you need to source the hook from one of your shell initialization files.

~/.bashrc
source /usr/share/doc/pkgfile/command-not-found.bash
  • Example for Zsh:
~/.zshrc
source /usr/share/doc/pkgfile/command-not-found.zsh

An alternative "command not found" hook is also provided by the AUR package command-not-foundAUR, which will generate an output like the following:

$ abiword
The command 'abiword' is been provided by the following packages:
abiword (2.8.6-7) from extra
	[ abiword ]
abiword (2.8.6-7) from staging
	[ abiword ]
abiword (2.8.6-7) from testing
	[ abiword ]

for it to work, add the following to a zshrc:

[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh

See also