Creative Commons License

This work is licenced under a Creative Commons Licence.

User login

Narrow Terminal Tip

Just a quick tip. If you're working in a terminal and want to parse the output of a command, you can have issues with commands that try to limit their output dependant on your terminal width. An example of this is "dpkg -l" which lists all the packages installed on a machine (first few lines shown below)

ii  acl                   2.2.45-1                       Access control list utilities
ii  acpi                  0.09-3ubuntu1                  displays information on ACPI devices
ii  acpi-support          0.109                          a collection of useful events for acpi
ii  acpid                 1.0.4-5ubuntu9                 Utilities for using ACPI power management
ii  acroread              8.1.2-0medibuntu6              Adobe Reader - binary files - Medibuntu pack

Problems can be encountered when packages names get particularly long, and they get truncated. A simple way around this can be to change your terminal's environment via COLUMN. By prefixing COLUMN=250 before the command, the command output is given as if your terminal was really 250 columns (effectively characters) wide. Simple, quick, and easy if for whatever reason you can't resize your terminal.

It was pointed out to me that the reason that an arguably more elegant solution is to pipe the output through cat. Now, initially this seems perverse - cat shouldn't change the output, and this would be a prime candidate for a useless use of cat award. However, with most programs that output columns to the terminal, dpkg detects where it is outputting, and if it is outputting to a tty (i.e. an interactive terminal) it will shrink columns to fit the width of the screen make everything easier to read. If you pipe this through cat (or I believe any other process), it doesn't perform this (often) useful little tweak for you. Useful to know if you're going to be scripting the output of dpkg -l (for example to create a list of all your installed packages and versions in a concise manner).