Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I tried to install Gnome 3 on Debian Testing following this explanation. However, this didn't work and left me without any graphical user interface.

At the moment I try to fix that and I realised there is a long list of packages marked as manually installed. I stored a (line-break seperated) list of the packages that - in my opinion - should be marked as auto installed (nearly all of them).

Now I want to run apt-mark auto for this list.

How do I do that?

P.S.: I also would appreciate if somebody tells me that this is not a good idea (if it isn't).

share|improve this question
up vote 7 down vote accepted

You can use xargs:

 cat /path/to/file | xargs apt-mark auto

This should work if there is one package name per line in the text file /path/to/file.

Another option would be to use a for loop:

 for pkg in `cat /path/to/file`; do apt-mark auto $pkg; done

The second way might be useful if you have a similar problem where the command can't be called with a list of parameters but you have to call it once for each parameter you have. But in your case it's not that elegant of course... :)

Btw I assume that you are using bash.

Note: On my system apt-mark --help says:

Usage: apt-mark [options] {markauto|unmarkauto} packages...

And also:

apt-mark is deprecated, use apt-get markauto/unmarkauto.
share|improve this answer
With xargs, you can just write </path/to/file xargs apt-mark auto; and it'll cope with any whitespace separation between package names, not necessarily newlines (xargs has quoting issues but Debian package names don't contain any problematic character so it's ok here). An even simpler method is apt-mark auto $(cat /path/to/file) (which, again, works without requiring any special precaution because package names don't contain special characters). – Gilles Jul 12 '11 at 21:06

It sounds like you want to dump your list of files into "apt-mark auto" one at a time. This pseudo-code should get you started:

while read pkgname; do apt-mark auto $pkgname; done <list_of_packages
share|improve this answer
Why you calling this pseudo-code? It does work. – Tshepang Jul 12 '11 at 17:27
True, it does. There's just no sanity checking, error reporting, etc... – pboin Jul 12 '11 at 17:52

Run the following script with python scriptname.py list-of-packages.txt as root:

import subprocess
import sys

filename = sys.argv[1]
with open(filename) as f:
    packages = f.read()
    packages = packages.split()
    packages = " ".join(packages)
    cmd = "apt-mark auto " + packages
    subprocess.call(cmd, shell=True)

I expect that this wouldn't be a problem since having GNOME implies that you already have Python installed.

share|improve this answer
You've just reinvented xargs, minus its quoting issues but they're not a problem here. – Gilles Jul 12 '11 at 21:07
I was sure there was a better way of doing things. It just so happens I was the first to answer so I thought something sub-optimal is better than nothing :) – Tshepang Jul 12 '11 at 22:00

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.