Ubuntu – List names of all packages starting with a specific word

aptcommand linepackage-management

Say I want to install all the ubuntu-wallpapers packages, so I would enter the following at the terminal:

sudo apt install ubuntu-wallpapers*

I am trying to get the same effect using

dpkg --set-selections < ./pkgs.txt

The problem is, this method does not support the * wildcard in the pkgs.txt file.

i was able to get the exact list of packages using

apt-cache search ^ubuntu-wallpapers

but I get the descriptions too. Is there a way to get only the package names so I can redirect the output to the pkgs.txt file?

Best Answer

You can use apt-cache pkgnames to list only the names of all packages starting with a specific prefix:

$ apt-cache pkgnames ubuntu-wallpaper
ubuntu-wallpapers-karmic
ubuntu-wallpapers-vivid
ubuntu-wallpapers-maverick
ubuntu-wallpapers-utopic
ubuntu-wallpapers-wily
ubuntu-wallpapers-quantal
ubuntu-wallpapers-raring
ubuntu-wallpapers-precise
ubuntu-wallpapers-lucid
ubuntu-wallpapers-natty
ubuntu-wallpapers
ubuntu-wallpapers-trusty
ubuntu-wallpapers-oneiric
ubuntu-wallpapers-saucy
ubuntu-wallpapers-xenial

See man apt-cache for more info.

Alternatively, you could process the output of apt-cache search and display only the first column by piping it e.g. through one of these commands below or anything similar:

  • cut -d' ' -f1
    
  • grep -Eo '^\S+'
    
  • sed 's/\s.*//'
    
  • awk '{print $1}'
    
Related Question