207

If I use apt-get install -qq mono-devel, I expect it to be quiet except for errors, according to the help:

-qq No output except for errors

Instead I get:

Extracting templates from packages: 100%
Selecting previously unselected package binfmt-support.
(Reading database ... 84711 files and directories currently installed.)
Unpacking binfmt-support (from .../binfmt-support_2.0.8_i386.deb) ...
Selecting previously unselected package cli-common.
Unpacking cli-common (from .../cli-common_0.8.2_all.deb) ...
Selecting previously unselected package libgdiplus.
Unpacking libgdiplus (from .../libgdiplus_2.10-3_i386.deb) ...
Selecting previously unselected package libmono-2.0-1.
Unpacking libmono-2.0-1 (from .../libmono-2.0-1_2.10.8.1-1ubuntu2.2_i386.deb) ...
Selecting previously unselected package libmono-2.0-dev.
Unpacking libmono-2.0-dev (from .../libmono-2.0-dev_2.10.8.1-1ubuntu2.2_i386.deb) ...
Selecting previously unselected package libmono-corlib4.0-cil.
Unpacking libmono-corlib4.0-cil (from .../libmono-corlib4.0-cil_2.10.8.1-1ubuntu2.2_all.deb) ...
Selecting previously unselected package libmono-system-xml4.0-cil.
Unpacking libmono-system-xml4.0-cil (from .../libmono-system-xml4.

and more...

In fact, a couple hundred lines worth of output. This does not appear to match up with no output except for errors.

How do I actually get apt-get install to print out only when there are errors keeping it from installing?

jbtule
  • 2,170

7 Answers7

144

The man page for apt-get is as follows:

NAME
       apt-get - APT package handling utility -- command-line interface

SYNOPSIS
       apt-get [-asqdyfmubV] [-o=config_string] [-c=config_file] [-t=target_release]
               [-a=architecture] {update | upgrade | dselect-upgrade | dist-upgrade |
               install pkg [{=pkg_version_number | /target_release}]...  | remove pkg...  |
               purge pkg...  | source pkg [{=pkg_version_number | /target_release}]...  |
               build-dep pkg [{=pkg_version_number | /target_release}]...  |
               download pkg [{=pkg_version_number | /target_release}]...  | check | clean |
               autoclean | autoremove | {-v | --version} | {-h | --help}}

The -q or -qq flag should go before the command, like so:

apt-get -qq upgrade

muru
  • 207,228
Mike
  • 1,624
113

We faced the same problem. apt-get install -qq removes most of the outputs but annoying "(Reading database ..." still persist.

We took a look in the source of apt and discover that the output is produced by dpkg that was forked by apt. Then the source of dpkg shows that the annoying soutput is only issued when isatty(1) is true. This is only the case when the fork uses pty instead pipe. Back to apt, there is a undocumented configuration variable that allows to use pipe instead pty which then solve the problem:

apt-get install -qq -o=Dpkg::Use-Pty=0 <packages>

Expecting that can help others.

69

A simple redirection could do this. It's not exactly what you had in mind, I'm sure, but it sure as hell works :)

In short, just whack > /dev/null on the end of any command where you want to redirect all the stdout into nothingness. Things outputted on stderr will still show in the console.

$ sudo apt-get update > /dev/null
[sudo] password for oli: 
$ 

No junk! And here's what happens if we're silly and break something:

$ apt-get cheese > /dev/null
E: Invalid operation cheese
$
Oli
  • 299,380
8

As you can see here and here
You can do:

export DEBIAN_FRONTEND=noninteractive
apt-get -yq install [packagename]
export DEBIAN_FRONTEND=dialog

Or one line:

DEBIAN_FRONTEND=noninteractive apt-get -yq install [packagename]
Mark
  • 81
5

With apt-get -qq install -y PACKAGE 2> /dev/null you can:

  1. Show only the errors with -qq.
  2. Send the errors to /dev/null (not show) so with that you can install a package with zero output.
Eliah Kagan
  • 119,640
trxgnyp1
  • 159
1

For me this works perfectly for fully silent/zero output while installing cause NULL STDIN and STDOUT.

DEBIAN_FRONTEND=noninteractive apt-get install -qq [packagename] < /dev/null > /dev/null

Hope it helps!!

-1

You can use a python script to do literally anything with the stdout and stderr of every command. For example, if you want to see a dynamic output including only the last line of the output, you can use the following script :

#!/usr/bin/python3
import subprocess, sys
process = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE)
while process.poll() is None:
  stdout = process.stdout.readline().decode()[:-1]
  print(stdout,end='\r')
print()

If you know how to work with strings in python, you can tweak the script to print only the lines you want to be printed, in whatever format you wish.

Save the above code in a file such as run.py. Then you can run any command to see only the last line of the output dynamically. For example:

./run.py sudo apt-get install <package>

or:

./run.py sudo apt-get update
Note 1: Don't forget to give exec permission to your script:
chmod +x run.py
Note 2: You can make a proper symlink for a more convenient usage (or alternatively add the script path to $PATH environment variable which I do not suggest):
sudo ln -s <path/to/yourscript.py> /usr/bin/run

Afterwards, you can only use:

run <command-with-desired-output-format>