Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change width of man command ouput

I use Guake terminal emulator a lot. It's the best thing since sliced bred IMO.

But one thing has been bugging me, when I want to read man pages the default width of the output is the width of the terminal windows, which in my case is always full screen so it's a bit difficult to read.

Is there a way I can make the default width of the output of man command a, pleasant to read, 80 characters?

The man page for man has this part:

   MANWIDTH
          If  $MANWIDTH  is set, its value is used as the line length for which manual pages should be formatted.  If it is not set,
          manual pages will be formatted with a line length appropriate to the current terminal (using an ioctl(2) if available, the
          value  of  $COLUMNS,  or  falling  back  to 80 characters if neither is available).  Cat pages will only be saved when the
          default formatting can be used, that is when the terminal line length is between 66 and 80 characters.

But I cant figure out where to change it.

I tried adding the line:

MANWIDTH 80

to /etc/manpath.config and ~/.bashrc, but with no result.

like image 657
Kok Nikol Avatar asked May 11 '15 16:05

Kok Nikol


People also ask

What is the output of man command?

man command in Linux is used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the command which includes NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS and SEE ALSO. 1.

What is man in command prompt?

The man command provides reference information on topics, such as commands, subroutines, and files. The man command provides one-line descriptions of commands specified by name. The man command also provides information on all commands whose descriptions contain a set of user-specified keywords.

What is man top in Linux?

DESCRIPTION top The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

What feature does the F switch in top provide?

Typing f and F activates Fields-Management. According to the top man page: These keys display a separate screen where you can change which fields are displayed, their order, and also designate the sort field. I've added PPID (Parent Process Id), SWAP, and nTH as well.


2 Answers

As pointed out in other answers, setting and exporting MANWIDTH properly is the way to go.

I would avoid hardcoding it, or else it will overflow / have ugly linebreaks when your terminal emulator window is more narrow than that value:

NAME
       grep, egrep, fgrep - print lines that match
 patterns

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep [OPTION...] -e PATTERNS ... [FILE...]
       grep [OPTION...] -f PATTERN_FILE ... [FILE.
..]

DESCRIPTION
       grep  searches  for  PATTERNS  in  each  FI
LE.  PATTERNS is one or more
       patterns separated by newline characters, a
nd  grep  prints  each  line
       that  matches a pattern.  Typically PATTERN
S should be quoted when grep
       is used in a shell command.

Here's what I use, in a handy alias:

alias man='MANWIDTH=$((COLUMNS > 80 ? 80 : COLUMNS)) man'

This sets MANWIDTH to 80 if the terminal window is wider than that, and to COLUMNS (the current width of the terminal window) if it is more narrow.

Result in a wide window:

NAME
       grep, egrep, fgrep - print lines that match patterns

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep [OPTION...] -e PATTERNS ... [FILE...]
       grep [OPTION...] -f PATTERN_FILE ... [FILE...]

DESCRIPTION
       grep  searches  for  PATTERNS  in  each  FILE.  PATTERNS is one or more
       patterns separated by newline characters, and  grep  prints  each  line
       that  matches a pattern.  Typically PATTERNS should be quoted when grep
       is used in a shell command.

Result in a narrow window:

NAME
       grep,  egrep, fgrep - print lines that
       match patterns

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep  [OPTION...]  -e   PATTERNS   ...
       [FILE...]
       grep  [OPTION...]  -f PATTERN_FILE ...
       [FILE...]

DESCRIPTION
       grep searches  for  PATTERNS  in  each
       FILE.    PATTERNS   is   one  or  more
       patterns    separated    by    newline
       characters,  and grep prints each line
       that  matches  a  pattern.   Typically
       PATTERNS should be quoted when grep is
       used in a shell command.
like image 195
Benjamin W. Avatar answered Sep 24 '22 21:09

Benjamin W.


That's an environment variable.

Try:

MANWIDTH=80
export MANWIDTH
man bash

If you want that set permanently then you can add those first two lines to your shell session startup scripts or similar.

like image 29
Etan Reisner Avatar answered Sep 23 '22 21:09

Etan Reisner