How to list all aptitude user tags or the user tags for a package?

If you installed the packages with aptitude and appended the --add-user-tag <tag> option you can list the user tags for a package by running:

aptitude show <package_name>

and the last line of the output should display the user tags.

You can use the following to search in all installed packages

aptitude show '~i' | grep "User Tags"

The following commandline will return one user tag per line:

aptitude show '~T' | sed -n '/^User Tags: /{s/^User Tags: //;s/, /\n/g;p}' | sort -u

This will pipe the information of all packages in the package database (~T) to sed, which will:

  • -n not print the pattern space (the line) automatically after each command cycle; together with /User Tags/ and p it basically mimics grep
  • /^User Tags: / only do the command group ({}) on lines matching this regular expression
  • s/^User Tags: // substitute "User Tags: " at the beginning of the line with an empty string
  • s/, /\n/ substitude commata+space separating multiple user tags with a newline character
  • p print the resuilting pattern space

sed's output (the user tags for each package, one per line) is then piped to sort -u to weed out multiple mentions of the same tag.


With the following command you don't need pipes or grep:

aptitude search '?user-tag()' -F '%p %T'

This finds all packages that have a user-tag, and sets the output format with -F to %p %T for the packge name and the user-tag.

You can add anything to the search query to further limit the results, e.g. to list only installed packages with user-tags:

aptitude search '~i?user-tag()' -F '%p %T'

Tags:

Apt

Aptitude