Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example:

The following command will install all packages that match it's pattern:

  sudo apt-get install k3b-*

If I want to use that instruction but don't want to install one specific package with broken dependencies, how do I do that?

I have tried this but not works.

sudo apt-get install "$(apt-cache --no-generate pkgnames k3b | grep -v extrathemes | tr '\n' ' ')" :

 sam@/home/sam/code/ros/ai/cram/roslisp_repl$ sudo apt-get install      "$(apt-cache --no-generate pkgnames k3b | grep -v extrathemes | tr '\n' ' ')"
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 E: Unable to locate package k3b-dbg k3b-data k3b 


Thank you~

share|improve this question
Sam - I'm confused - you've marked the question as solved but have edited the question saying otherwise... is the question solved or not - please update as appropriate. – fossfreedom Sep 18 '11 at 10:26
Yes,enzotib's answer is solved my question with 2 steps. But con-f-use's answer is trying to solve my question with another way(1 step) but with errors. I want to learn more so I revise my origin post to let @con-f-use know what I am tring. – sam Sep 18 '11 at 10:39
You should remove double quotes around $(instructions). – enzotib Sep 18 '11 at 10:46
Won't sudo apt-get install k3b-* fail if there is a file that matches the pattern in the current directory? – svick Sep 18 '11 at 17:37
I haven't happened this situation,and I solve it in second way by removing "" quote. – sam Sep 18 '11 at 23:14
up vote 4 down vote accepted

You can do

list=$(apt-cache --names-only search ^k3b-* | awk '{ print $1 }' | \
    grep -v bad-pkg)
sudo apt-get install $list
share|improve this answer
nice O+ +1 from me – Rinzwind Sep 18 '11 at 10:38
What is 'nice O+ +1' ? – sam Sep 18 '11 at 23:12

Say you don't want to install the k3b-extrathemes package. There might be no practical way to do this but to list all the packages except for the one: sudo apt-get install k3b-data k3b-dbg.

However you can do that with some aid:

sudo apt-get install $(apt-cache --no-generate pkgnames k3b \
    | grep -v extrathemes | tr '\n' ' ')

That's not terribly partical. apt-cache ... returns the name of the packages, grep -v PACKAGENAME excludes the packages and the tr command replaces new lines by spaces.

share|improve this answer
I have revised my origin post for this instruction's result.Why can't locate packages? – sam Sep 18 '11 at 10:13
You should remove double quotes around $(instructions). – enzotib Sep 18 '11 at 10:47
Thank you~ It works! – sam Sep 18 '11 at 10:52

I discovered a much simpler way of doing this:

sudo aptitude install <package>

This will use aptitude Install aptitude instead of apt-get Install apt - which provides you with more options. When you see something like the following:

The following NEW packages will be installed:
0 packages upgraded, 12 newly installed, 0 to remove and 0 not upgraded.
Need to get 130 MB/130 MB of archives. After unpacking 216 MB will be used.
Do you want to continue? [Y/n/?]

Instead of pressing 'y', type the following:


That's a '-' followed by the name of the package to skip. Then you can proceed with the installation as per normal.

share|improve this answer
Newer releases don't install aptitude by default, but you can easily install it using sudo apt-get install aptitude or from the Software Center. – Mechanical snail Jan 18 '13 at 6:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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