How to list packages with files in a particular directory?

Carlos

I'm switching to CentOS from another distribution, and I'm not used to working with yum. I'd like to know if there's a way to know which installed packages have files in a directory.

For example I'd like to know which packages have files within /usr/share/applications.

Looking at what yum provides I saw there's a way to see installed packages (list installed) but even providing -q doesn't get me just the names of the packages. I saw no option to list contents of a single package however.

Is it possible? How could I do it?

slm

There isn't a way to do this using yum but you can craft a rpm command that will do mostly what you want. You'll have to utilize the --queryformat option and iterate through the array of filenames using the little known option [..] in the --queryformat.

NOTE: All these features are discussed in the manual for RPM, Maximum RPM: Taking the Red Hat Package Manager to the Limit.

$ rpm -qa --queryformat '[%{NAME}: %{FILENAMES}\n]' | \
    sed 's#\(/.*/\).*$#\1#' | sort -u | grep '/usr/sbin' | head -10
abrt-addon-ccpp: /usr/sbin/
abrt-addon-pstoreoops: /usr/sbin/
abrt-addon-vmcore: /usr/sbin/
abrt-dbus: /usr/sbin/
abrt: /usr/sbin/
alsa-utils: /usr/sbin/
aoetools: /usr/sbin/
at: /usr/sbin/
authconfig: /usr/sbin/
avahi-autoipd: /usr/sbin/
...

Details

The above --queryformat iterates over the array macro %{FILENAMES} via the [...] notation, printing the name (%{NAME}) of the package they're contained in, along with their full installed path.

Example
$ rpm -q --queryformat '[%{NAME}: %{FILENAMES}\n]' fatrace
fatrace: /usr/sbin/fatrace
fatrace: /usr/sbin/power-usage-report
fatrace: /usr/share/doc/fatrace-0.5
fatrace: /usr/share/doc/fatrace-0.5/COPYING
fatrace: /usr/share/doc/fatrace-0.5/NEWS
fatrace: /usr/share/man/man1/fatrace.1.gz

With this type of output we simply need to chop off the trailing filenames from the above paths. For this I used sed. I then run the output through sort -u to condense any duplicate lines since often times, many packages will install a multitude of files into a single directory. Finally I use grep ... to find the packages which have files in a given directory. To facilitate this further you could do this:

grep $(pwd)
Example
$ pwd
/usr/sbin

$ rpm -qa --queryformat '[%{NAME}: %{FILENAMES}\n]' | \
    sed 's#\(/.*/\).*$#\1#' | sort -u | grep $(pwd)

A list of just package names

To get just the names of the packages in a unique list you can do the following:

$ rpm -qa --queryformat '[%{NAME}: %{FILENAMES}\n]' | \
    sed 's#\(/.*/\).*$#\1#' | sort -u | grep $(pwd) | \
    awk -F: '{print $1}' | head -10
abrt-addon-ccpp
abrt-addon-pstoreoops
abrt-addon-vmcore
abrt-dbus
abrt
alsa-utils
aoetools
at
authconfig
avahi-autoipd

References

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to view list of backup files on a particular date

分類Dev

How to properly list files of a directory?

分類Dev

how to extract the properties of all files and folders of a particular directory using vbscript?

分類Dev

How to get list of files in directory smb libcurl?

分類Dev

How to get a list of files in the directory os x?

分類Dev

list files not originating from packages

分類Dev

How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

分類Dev

List Files which don't contain a particular string at a particular line

分類Dev

Vue.js webpack : how to get the list of files in a directory?

分類Dev

How to customize bash autocomplete to list the files in another directory

分類Dev

How do I list the files having particular strings from group of directories in bash?

分類Dev

Swift delete all files from particular Document Directory Location

分類Dev

Display files contain inside a particular directory by using C++ in LINUX

分類Dev

Using files in directory that are matching with a list

分類Dev

WARNING:dpkg:Files list file missing for packages

分類Dev

How to count files in a directory

分類Dev

list.files() all files in directory and subdirectories

分類Dev

What is the command to remove files in Linux from a particular directory which are owned by a particular user?

分類Dev

How to list all installed packages

分類Dev

How to print a element of list in a particular format

分類Dev

How to list characters of a particular frequency in a string

分類Dev

R how to use files in the same packages

分類Dev

list files with different extensions from a directory

分類Dev

List of recently changed files for a directory and all subdirectories

分類Dev

Create a list of files in a directory with a certain char

分類Dev

How to unzip files into the current directory?

分類Dev

How to get a list of all files in directory with Google Drive API(v3)

分類Dev

How can i get all files on disk with a specific extension using 'Directory.getFiles' and save them in a list

分類Dev

How to a list private Python packages as Conda requirement?

Related 関連記事

  1. 1

    How to view list of backup files on a particular date

  2. 2

    How to properly list files of a directory?

  3. 3

    how to extract the properties of all files and folders of a particular directory using vbscript?

  4. 4

    How to get list of files in directory smb libcurl?

  5. 5

    How to get a list of files in the directory os x?

  6. 6

    list files not originating from packages

  7. 7

    How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

  8. 8

    List Files which don't contain a particular string at a particular line

  9. 9

    Vue.js webpack : how to get the list of files in a directory?

  10. 10

    How to customize bash autocomplete to list the files in another directory

  11. 11

    How do I list the files having particular strings from group of directories in bash?

  12. 12

    Swift delete all files from particular Document Directory Location

  13. 13

    Display files contain inside a particular directory by using C++ in LINUX

  14. 14

    Using files in directory that are matching with a list

  15. 15

    WARNING:dpkg:Files list file missing for packages

  16. 16

    How to count files in a directory

  17. 17

    list.files() all files in directory and subdirectories

  18. 18

    What is the command to remove files in Linux from a particular directory which are owned by a particular user?

  19. 19

    How to list all installed packages

  20. 20

    How to print a element of list in a particular format

  21. 21

    How to list characters of a particular frequency in a string

  22. 22

    R how to use files in the same packages

  23. 23

    list files with different extensions from a directory

  24. 24

    List of recently changed files for a directory and all subdirectories

  25. 25

    Create a list of files in a directory with a certain char

  26. 26

    How to unzip files into the current directory?

  27. 27

    How to get a list of all files in directory with Google Drive API(v3)

  28. 28

    How can i get all files on disk with a specific extension using 'Directory.getFiles' and save them in a list

  29. 29

    How to a list private Python packages as Conda requirement?

ホットタグ

アーカイブ