3

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?

  • General advice: always quote patterns with e.g. asterisks or other special symbols. In your case, the shell will try to interpret ubuntu-wallpapers* as a glob, matching files in the current directory. It only works if you have no matching files in the current location, because then the glob will be preserved literally. The safe way to use it is sudo apt install 'ubuntu-wallpapers*' – Byte Commander Jan 11 '18 at 10:31
4

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

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.