> On 5/5/26 01:01, badli al rashid wrote:
> > I am trying to make Debian comply to GNU/Linux by removing some programs
> > like "apt purge $(dpkg -l | grep contrib | awk '{print$2}').

On Tue, May 05, 2026 at 16:35:24 +0800, badli al rashid wrote:
> something i want to acheive is to the following.
> 
> 1.  use just the main repo for apt and nothing else.
> 2. use libreoffice but i can not. as if i purge the contrib, it remove
> libreoffice.  I use calligra suite instead

The problem is, the command you're using does NOT purge all the
packages that came from the "contrib" repository.

dpkg -l does NOT show the repository that a package came from, and
therefore "grep contrib" is meaningless.  You're only going to match
packages that have the letters "contrib" in their name, or in their
one-line descriptions.

To see packages that came from the contrib repository, you can use
this command instead:

    apt list '?installed ?section(contrib)'

Here's what it gives me:


hobbit:~$ apt list '?installed ?section(contrib)'
ESC[32msteam-installerESC[0m/stable,now 1:1.0.0.83~ds-3 amd64 [installed]


Sadly, someone decided that it should automatically pipe through
less when stdout is connected to a terminal, and my $LESS settings
don't include -R by default, so I get terminal escape sequence
gibberish.

One can try to circumvent that, but it starts getting uglier:


hobbit:~$ apt list '?installed ?section(contrib)' | cat

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Listing...
steam-installer/stable,now 1:1.0.0.83~ds-3 amd64 [installed]


hobbit:~$ apt list '?installed ?section(contrib)' 2>/dev/null | cat
Listing...
steam-installer/stable,now 1:1.0.0.83~ds-3 amd64 [installed]


That's about as good as I think it'll get.

You seem to want to script this via a shell, but I think you may be
overthinking it.  Don't try to set up a fancy command with awk and
apt purge yet.  Just get the package listing.  It will probably be zero
packages, in which case you can just stop immediately.  If it's just one
or two packages, it'll be faster to type out "apt purge " and then copy
and paste the package names (or type them by hand), rather than trying
to parse the listing with awk.

Reply via email to