> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Identify the component of a Linux distribution that a file belongs to

> This guide explores DNF-based commands to identify packages owning files, list package contents, and filter file listings on Linux systems.

Discovering which package installed a specific file on your Linux system is invaluable when you need to restore default configurations after unintended edits. In this guide, we’ll explore DNF-based commands to:

* Find the package providing a file or command
* List all files in a package
* Filter package file listings

<Callout icon="lightbulb" color="#1CB2FE">
  These examples assume a DNF-based distribution (Fedora, RHEL, CentOS Stream). On older systems using `yum`, substitute `yum provides` and `yum repoquery`.
</Callout>

***

## Table of Common DNF Queries

| Command                                        | Purpose                                  | Example                        |                |
| ---------------------------------------------- | ---------------------------------------- | ------------------------------ | -------------- |
| `dnf provides <file>`                          | Identify package owning a file           | `dnf provides /etc/anacrontab` |                |
| `dnf provides <command>`                       | Find package that supplies a CLI command | `dnf provides docker`          |                |
| `dnf repoquery --list <pkg>`                   | List every file in *any* package         | `dnf repoquery --list nginx`   |                |
| `dnf repoquery --list <pkg> \| grep <pattern>` | Filter listed files by name or extension | \`...                          | grep '.conf'\` |

***

## 1. Find Which Package Owns a File

Suppose you’ve modified `/etc/anacrontab` and want to revert it to the distribution’s original version. Use:

```bash theme={null}
$ dnf provides /etc/anacrontab
cronie-anacron-1.5.2-4.el8.x86_64 : Utility for running regular jobs
Repo        : baseos
Matched from:
Filename    : /etc/anacrontab

cronie-anacron-1.5.2-6.el8.x86_64 : Utility for running regular jobs
Repo        : @system
Matched from:
Filename    : /etc/anacrontab
```

The output shows `cronie-anacron` as the provider. To restore:

```bash theme={null}
$ sudo rm /etc/anacrontab
$ sudo dnf install --refresh cronie-anacron
```

After reinstalling, the original `/etc/anacrontab` is back in place.

<Callout icon="triangle-alert" color="#FF6B6B">
  Removing system files can affect service behavior. Always backup configurations before deletion.
</Callout>

***

## 2. Discover Which Package Supplies a Command

Want the `docker` CLI but unsure which package includes it? Run:

```bash theme={null}
$ dnf provides docker
podman-docker-3.1.0-0.13.module_el8.5.0+733+9bb5dffa.noarch : Emulate Docker CLI
Repo        : appstream
Matched from:
Provide     : docker = 3.1.0-0.13.module_el8.5.0+733+9bb5dffa

podman-docker-3.3.0-0.17.module_el8.5.0+874+6db8bee3.noarch : Emulate Docker CLI
Repo        : appstream
Matched from:
Provide     : docker = 3.3.0-0.17.module_el8.5.0+874+6db8bee3
```

Here, `podman-docker` emulates the Docker CLI, so install it to use `docker`.

***

## 3. List All Files in a Package

To inspect every file a package ships—even if it isn’t installed locally—use:

```bash theme={null}
$ dnf repoquery --list nginx
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
...
/usr/lib/.build-id
```

This complete list helps you identify configuration files, binaries, libraries, and other assets.

***

## 4. Filter the File Listing

Narrow down to specific file types (e.g., configuration files) by piping to `grep`:

```bash theme={null}
$ dnf repoquery --list nginx | grep '\.conf'
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
```

Use any regex pattern to quickly locate files of interest.

***

## Further Reading

* [DNF Command Reference](https://dnf.readthedocs.io/)
* [Fedora Package Management](https://docs.fedoraproject.org/en-US/quick-docs/dnf/)
* [Red Hat Enterprise Linux Subscription Guide](https://access.redhat.com/documentation/en-us/red_hat_subscription_management/)

Practice these commands to become confident in managing package-owned files and restoring default configurations on your DNF-based Linux system.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/linux-system-administration-for-beginners/module/ca5e9d7c-9dac-4ecc-9e21-dafef5ef2641/lesson/d354e7d0-1479-4964-a400-65bc444ffdfa" />

  <Card title="Practice Lab" icon="installation" cta="Learn more" href="https://learn.kodekloud.com/user/courses/linux-system-administration-for-beginners/module/ca5e9d7c-9dac-4ecc-9e21-dafef5ef2641/lesson/1c82b7ef-7485-4d29-bff1-adf3706193db" />
</CardGroup>
