Linux Labs

Packages, services, and logs / Stage 2 of 13

Installed packages and their files

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 8 · on a machine · 5 min

Database record and files on disk

The package database holds records dpkg made at installation. The files on disk live a life of their own.

When dpkg installs a package, it writes to the package database the package's name, version, state and the list of every file it placed in the system. The line Status: install ok installed means the package is installed and configured, with no errors during installation.

After that the record changes only when dpkg itself handles the package — installing, upgrading or removing it. An rm that deletes the program file leaves the database alone. So the file list in the record and the contents of the disk can drift apart.

dpkg -L prints the package file list from the record, while ls checks the disk itself:

bash
dpkg -L lab-pkg-report
ls -l /usr/bin/lab-pkg-report

The dpkg -L list includes /usr/bin/lab-pkg-report, while ls prints No such file or directory.

Check yourself 1 question

You deleted /usr/share/doc/tree/TODO with sudo rm. What will dpkg -L tree print?

  • dpkg -L does not check files and reports no damage: it prints the recorded list.

  • The list comes from the database record, and rm does not change it. The missing file stays in the list; only ls checks the disk.

dpkg -L prints the list from the package record made at installation. Whether the file is on disk is shown by ls -l /usr/share/doc/tree/TODO: No such file or directory.

Key points

  • dpkg writes the package state and its file list to the package database.
  • Only dpkg operations change the record; deleting a file by hand leaves it alone.
  • dpkg -L prints the files from the record; ls checks whether they are on disk.
Ubuntu 24.04
Loading…