You're likely familiar with aptitude and its linguistically sensical search syntax (vis-à-vis apt-get's separate "apt-cache search"), so we'll use that to craft a one-liner for search and install.
My Usual Method
First, we'll want aptitude to return only the package name instead of the usual status, name, and description. To do so, use the -F (format) %p (package's name) and then your search string (here, "gtk-theme")aptitude search -F %p gtk-themeRunning this returns a list of packages containing the search sting. Alas, this also includes a few packages we don't want. Use the grep -v flag to remove these from the results list. We could pipe the list to grep multiple times, or we could create a simple regex phrase containing all the items we don't want to include.
Here, that list is the packages gtk-theme-config and gtk-theme-switch so we'll look for results with config|switch. Note the use of single quotes is important, and the pipe within them must be escaped with the backslash.
grep -v 'config\|switch'Once we have a list of only the packages we care about, we will send those to xargs which will execute commands from standard input (in this case, the previous piped input.) Since the one-liner cannot prompt for interaction, we add the -y flag to the aptitude install.
xargs aptitude install -yCombining these steps, we get the following one-line command. Voila!
aptitude search -F %p gtk-theme | grep -v 'config\|switch' | xargs aptitude install -y
Alternative Method
Given that aptitude will not try to install already installed packages, the above works just fine. If you're super-retentive and want your search to only attempt packages that are not already installed, replace the first step above with a search for uninstalled packages and a grep for the package name you are interested in.For instance, to install all icon-theme packages not currently installed, your first query would be:
aptitude search \!~i | grep -i icon-themeThen we need to grab just the package name, so we'll pipe it to sed to grab only the second column (enjoy parsing that regex sed statement...)
sed -n 's/^... \([^ ]*\) * -.*$/\1/p'...and the full search would be thus (note the dropping of the grepping out of the config|switch in this example):
aptitude search \!~i | grep -i icon-theme | sed -n 's/^... \([^ ]*\) * -.*$/\1/p' | xargs aptitude install -y