5

Following my own counsel I started using user-tags when working on projects, but now I don't remember how I called some of these tags and this cancels their usefulness. Is there a way to get those names back?

1

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'
4

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"
  • I have updated the answer. – cioby23 May 16 '14 at 14:16
  • BTW, the sudo is not necessary ;) – Braiam May 16 '14 at 14:17
  • Yes I have tested without sudo also but I have added here thinking that on some systems it will not work properly – cioby23 May 16 '14 at 14:18
  • 1
    BTW, your last command wont work if I have packages installed using dpkg, this aptitude show '~i' | grep "User tags" would work always. – Braiam May 16 '14 at 14:27
  • Sorry is "User Tags" at the end. – Braiam May 16 '14 at 14:38
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.