CENTER(1) Manual Page

  • Home
  • Back

  • CENTER(1) General Commands Manual CENTER(1)

    centercenter align text

    center [-elr] [-t width] [-w width] [file ...]

    The center utility reads files sequentially, writing each line center aligned to the standard output. The file operands are processed in command-line order. If file is a single dash (‘-’) or absent, center reads from the standard input. When run without arguments, the width on which the output should be centered is automatically determined. When the output device is a TTY, this is done via the () function. When the output device isn't a terminal then the user is required to pass a width via the -w flag.

    The options are as follows:

    , --ignore-ansi
    Do not take ANSI color escape sequences into account when centering input. This will cause input containing ANSI color escape sequences to fail to be visually centered.
    , --longest
    Center the file as a whole instead of centering each line individually. In otherwords each line is centered as if it has the length of the longest line. This is useful for tasks like centering source code.
    , --spaces
    Display tabs using spaces. By default center displays tabs using a literal tab character, however this can cause the output to not appear as intended. This is because tabs align to the next column that is a multiple of 8 instead of always displaying as 8 columns. This flag ensures that every tab character will display as 8 columns or the amount of columns specified by the -t flag.
    width, --tabsize=width
    Treat tab characters as if they have a width of width. If this option is not specified, tabs are assumed to have a tab width of 8 columns.
    width, --width=width
    Center align the input as if the output device has a width of width. This option is required when the output device is not a terminal.

    The center utility exits 0 on success, and >0 if an error occurs.

    Center align the contents of file1 and file2 to the standard output:

    $ center file1 file2

    Center align a calendar and then follow it with the contents of the file file1, writing the output to the file file2. Align the calendar as if the output device has a width of 80 columns.

    $ cal | center -w 80 | cat - file1 > file2

    Center align the contents of file1 and write the output to file2 as if the output device had the same width as the current TTY. This requires non-standard extensions, and you should refer to the tput(1) manual page.

    $ center -w `tput cols` file1 > file2

    Center align the C source code file main.c assuming a tab width of 4 and view it in less(3).

    $ center -lr -t 4 center.c | less

    cal(1), cat(1), less(1), tput(1), isatty(3)

    Thomas Voss <[email protected]>

    November 16, 2022 MangoOS