Linux debian list packages

Listing all user-installed packages in Debian

For a cyber security competition I participate in, I’m given a Debian virtual machine with many packages installed and asked to clean extraneous or malicious packages. In the past, I’ve used dpkg -l | grep [searchterm] and a list of common packages to preform this task. However, this is extremely inefficient and time-consuming. To speed up my task, is there a way to search through the list of packages installed on a system for which processes have been installed by a user and are not system «default» packages?

9 Answers 9

This command may shorten your work:

It is supposed to show what packages were installed «manually». It is not 100% reliable though, as many automatically installed packages are flagged as manually installed (because of reasons too long to describe here).

You may also (if allowed) run security tools such as clamav and/or rkhunter to scan your computer for malicious programs.

Below is a line from a «health» script I run on my desktop every night. Besides gathering information from sensors, network usage, HDD temperature, etc. it also gets a list of all the software I’ve installed manually from the command line.

I’m running Kubuntu 14.04.5 (Trusty) at the moment and I don’t know the details of any differences between Ubuntu and Debian’s package management, but hopefully this will work for you as well as it does for me.

( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon | egrep '^Commandline:' | egrep 'install' 1>>installed_packages.txt 

All Packages

Most all the code that I found for this question used a search from the history log:

cat /var/log/apt/history.log | grep 'apt-get install ' 

or listed all Debian packages installed on the machine:

Manually Installed

I found the above answers to be inadequate as my history log was incomplete and I didn’t want to do the work to separate built-in packages with manually installed packages. However, this solution did the trick of showing only manually initiated installed packages. This one uses the log: /var/log/dpkg.log , and it should be executed as a Bash script.

#!/usr/bin/env bash parse_dpkg_log() < < for FN in `ls -1 /var/log/dpkg.log*` ; do CMD="cat" [ $== "gz" ] && CMD="zcat" $CMD $FN | egrep "5 install" | awk '' \ | awk -F":" '' done > | sort | uniq > list_installed=$(parse_dpkg_log) list_manual=$(apt-mark showmanual | sort) comm -12 <(echo "$list_installed") <(echo "$list_manual") 

This takes into account also packages installed with aptitude (not only apt install or apt-get install , like Benny Hill's answer which I based on):

( ( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon ; ( zcat $( ls -tr /var/log/aptitude.*.gz ) ; cat /var/log/aptitude ) ) | egrep '^Commandline:.*install|^\[INSTALL\]' | sed 's#Commandline: ##' | awk '/INSTALL/ < print $2 >; !/INSTALL/ < print $0 >; ' 1>installed_packages.txt 

Example output (the last line comes from aptitude logs):

apt-get install nodejs apt install tidy mc:amd64 

You may also look at the file /var/lib/apt/extended_states.

cat /var/lib/apt/extended_states | grep -B2 'Auto-Installed: 0' 

This is useful if you want to know what was installed on an old partition.

Читайте также:  Finding files in linux grep

The following Bash command works for me in Debian 10 (buster). It prints all manually installed packages minus the ones that came from your Debian installation (in other words, the packages that you installed with apt install ):

sudo grep -oP "Unpacking \K[^: ]+" /var/log/installer/syslog \ | sort -u | comm -13 /dev/stdin <(apt-mark showmanual | sort) 

sudo is needed to search through /var/log/installer/syslog . You could also save this installer package list somewhere else if you don't want to use sudo every time.

Someone wrote a program generate a list of all packages manually installed (by users, by admin/root, or both), as determined by the Debian package system. It inspects Debian's apt-history log, and then combines the reports from the apt-mark program. Apt-mark includes packages which were manually installed via use of the 'dpkg' system directly by users, not just ones installed via users through their package manager utility (Apt, Synaptic, Software Center, etc.). If you lack the apt-mark utility, you can tell it do just do the history inspection instead.

List User Installed Debian Packages Utility

List all packages manually installed (by users, by admin/root, or both), as determined by the Debian package system.

An older question but a solution I came up with after finding this and a couple of other questions for a slightly different task. Trying to keep up to date a list of installed packages for system rebuilds. I found the following works pretty well:

comm -12 <(apt list --installed 2>/dev/null | cut -d '/' -f 1 | sort) <(history | grep -e "apt\(-get\)\? install" | grep -v -e "grep -e" | grep -v "./" | cut -d ' ' -f10 | sort) 

This takes the list of all installed packages and compares to the history for packages being installed.

I'm assuming that packages are not being installed by evil actors trying to hide their tracks. Also a slightly nasty command apt list in a script however it does seem to work for now.

Источник

List All Installed Packages on Debian 11

This tutorial explains how to list all installed packages on Debian 11 Bullseye, previous and future versions, using different available techniques. It is also valid for Debian-based Linux distributions like Ubuntu.

By reading this tutorial, you will not only get simple instructions to list installed packages. You also will become more familiar with different package managers and their commands to administrate packages.

All instructions described in this tutorial include screenshots, making it easy for all Linux users to understand and follow them.

A Brief Introduction to Debian Package Managers

Before showing the practical techniques to list all packages on Debian, let’s introduce you to each.

The dpkg packages manager is the Debian base of all packages managers. Other known alternatives like apt or apt-get are frontends for dpkg, while aptitude is a frontend for apt.

The apt and apt-get frontends have important advantages over dpkg:

  • They can resolve dependencies.
  • They can install packages from the internet with a simple command.
  • They can provide information not only on local files but also on the remote.

The aptitude frontend is even better, including the following features:

  • It can resolve dependencies better than apt.
  • It informs how packages were installed (Manually or automatically).
  • It shows package changes in the system.
  • It offers both command line and interactive ncurses-based interfaces.

Listing All Installed Packages on Debian 11 Using dpkg/dpkg-query

This tutorial’s section explains how to list installed packages on Debian using both dpkg and dpkg-query tools.

The first command taught in this article will display a full list of all installed packages in our Debian 11 system using dpkg.

To do it, just run dpkg followed by the -l (list) flag, as shown in the screenshot below.

As you can see, the command will display the following five columns explained below.

Understanding dpkg Output

  • The first column will show 2 characters showing the package’s status (In the previous screenshot, “i”). Each letter has its own meaning, where the first shows desired package status as explained in the first line of the output. Possible desired status include:
  • i: The package is chosen to be installed.
  • r: The package is chosen to be removed.
  • p: The package is chosen to be purged (Removed, including all related files and directories).
  • u: The package status is unknown.
  • h: The package is kept and not managed by dpkg.
  • The second character (in the screenshot below also “i”) shows the package’s current status. Therefore if the second character is “r” and the first character is “i,” the meaning is the package is currently installed but selected for removal by the user. There are 8 possible letters for a package’s current status:
  • i: The package is installed.
  • n: The package is not installed in the system.
  • c: The package is not installed, but its configuration files remain.
  • f: The system failed to remove configuration files.
  • u: The package is unpacked.
  • h: The package installation started but wasn’t installed for an unknown reason.
  • f: The package was unpacked and partially configured but not installed for an unknown reason.
  • w: The package is waiting to be triggered by another package.
  • t: The package has been triggered by another package.
  • The second column displays package names.
  • The third column shows package versions.
  • The fourth column shows package architecture.
  • Finally, the fifth column shows package descriptions.

Another way to get the same output is the dpkg-query command, also followed by the -l flag, as shown in the image below.

The dpkg-query command has additional functions; for example, you can export the full list of installed packages to a file, which can be used later to install all listed packages in the file. This is a great method to install all packages in your current system in a new system.

The following command will create a file named installedpackages containing a list of all present packages. The name of the file is arbitrary.

You can see the exported list using reading commands like the less command, as shown below.

That’s how you can list installed packages in Debian Linux using both dpkg and dpkg-query commands. Keep reading below to list packages using alternative commands.

List All Installed Packages on Debian 11 Using apt

The apt (Advanced Package Tool) command is another package manager available on Debian and Ubuntu-based Linux distributions. Although finding information on packages with dpkg has advantages over apt, apt is better since it can resolve dependencies when installing software. But also apt can be useful to list packages and get information on them.

To print a full list of installed packages using apt, run the command shown below:

As you can see, the output is human-readable, but both dpkg and dpkg-query return a more user-friendly output sorted by columns.

Listing Packages by Status on Debian 11 Using aptitude

As said in the introduction of this article, the aptitude command is a frontend for apt with both interactive and command-line interfaces.

To list all installed files with a command-line interface using aptitude, run the aptitude command followed by the search ~i option, as shown in the following screenshot.

As you can see, the command returns 4 columns, where the first shows the package status (i means the package is installed). The second column shows how the package was installed; in the example above, the A letter indicates the package was automatically installed. The third column shows the package name, and the fourth column shows the package’s description.

To list installed packages using the interactive mode, run aptitude followed by the -i flag as shown below.

The output will show all installed packages, including their status. As shown in the previous screenshot, the list will start showing installed packages chosen to be removed. By scrolling down, you will see packages chosen to be held back and packages being automatically installed.

You also can display all installed packages sorted by status by simply running aptitude without flags.

As you can see in the image below, you can display all files in your system sorted by the following categories:

  • Upgradable packages.
  • New packages.
  • Not installed packages.
  • Obsolete and locally created packages.
  • Virtual packages.
  • Tasks.

This interactive interface is intuitive; browse them depending on the status of packages you want to list.

These are the available methods to list installed packages on Debian 11, its previous versions and Debian-based Linux distributions.

Conclusion

As you can see, each program (dpkg, dpkg-query, apt and aptitude) has its own advantages and disadvantages. Any Linux user level can run the commands explained in this tutorial to list installed packages in the system. Knowing your software is mandatory for any system administrator. All alternatives explained in this article are useful, being aptitude the best for users who don’t like to deal with the Linux terminal. My recommendation is to learn all of them to be familiar with different package managers.

Thank you for reading this tutorial explaining how to list all installed packages on Debian 11. I hope it was useful to you. Keep reading Linux Hint for more Linux tips and tutorials.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.

Источник

Оцените статью
Adblock
detector