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

There are some similar questions, but here is precisely what I would like to achieve and the dots which I am having trouble connecting:

  1. Query a list of "Manually Installed" packages (apt-mark showmanual works)
  2. Check each package for installed dependents
  3. Mark each such package as "Automatically Installed" (apt-mark auto <pkg ...> works)

So I think my command will look something like:

apt-mark showmanual | <esoteric apt/bash magic> | apt-mark auto -

Would that be correct?

Related Questions

  1. How do I find which packages could be set as automatically installed?
  2. Why are almost all packages marked as manually installed? (See also
share|improve this question
"There are some similar questions" ... you could provide links to the most relevant ones. – user25656 Apr 6 '13 at 2:50
up vote 2 down vote accepted

You could use Aptitude's why command:

for x in $(apt-mark showmanual)
  r="$(echo ${x} | sed -e 's/\([+.]\)/[\1]/g')"
  aptitude why ${x} | egrep -q "^i.* (Pre)?Depends +${r}( |$)" && apt-mark auto ${x}

Not tested, because it's not something I want to (have to un-)do on my machine.

share|improve this answer
The grep above is quite broad. It matches things like: aptitude why vimp vim-migemo Depends vim. The grep should check for lines starting with "i" and having the actual package looked for after it. I have submitted an edit to this answer. – Elrond Aug 27 '14 at 13:55
thank you very much guys, since it says "not tested" - i can confirm this does work, however (because of the grep part) relies on english locale - in some languages one will need to change environment before executing. – anx Mar 18 '15 at 11:50

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.