Redirection operator is limiting columns
I am running the following command to list the packages installed on a server.
$> dpkg -l
This is fine but when I do this
$> dpkg -l > list_of_packages_installed
I only get 106 columns of data and the rest is cut off. So all the rows are there but not all the data column-wise. There must be 开发者_高级运维something simple I am missing here?
The variable COLUMN is indeed responsible for this. The manpage of dpkg(8) contains under the section "ENVIRONMENT":
COLUMNS Sets the number of columns dpkg should use when display- ing formatted text. Currently only used by -l.
if COLUMNS is set in your environment then dpkg will use it. You can check with this command:
env | grep ^COLUMNS=
if that command outputs something like
COLUMNS=80
then you know that this variable is set in your environment. Note that this command:
echo $COLUMNS
does not tell you if it is an environment or a shell variable. COLUMNS can be set as a shell variable without being exported to the environment. With this command:
COLUMNS=$COLUMNS dpkg -l > k
you explicitely put the variable in the environment of dpkg. If it was not in your environment then it will be for this command only. Also note that the behaviour of dpkg in this respect is different between ubuntu and debian and also depends on the version. There have been a few bug reports on this topic. The dpkg in squeeze for example will set the column width so that all package names and version can be displayed in full if COLUMNS is not set in the environment and the output is not a tty.
Regards
精彩评论