man Command

Display manual pages and documentation for Linux commands, system calls, and functions.

Syntax

man [OPTION]... [SECTION] PAGE... man -k KEYWORD man -f PAGE

The man command displays the manual pages (documentation) for commands, system calls, library functions, and configuration files in Linux systems.

Common Options

Option Description
-k, --apropos Search manual page names and descriptions
-f, --whatis Display short description of command
-w, --where Show location of manual page files
-a, --all Display all matching manual pages
-u, --update Update manual page cache
-P, --pager Specify pager program to use
-H, --html Output in HTML format
-t, --troff Format for printing

Manual Page Sections

Section Description Examples
1 User commands ls, cp, mv, grep
2 System calls open, read, write, fork
3 Library functions printf, malloc, strlen
4 Device files null, zero, random
5 File formats passwd, fstab, hosts
6 Games fortune, cowsay
7 Miscellaneous ascii, regex, signal
8 System administration mount, fsck, iptables

Basic Examples

Viewing manual pages

# View manual for ls command man ls # View manual for specific section man 5 passwd # passwd file format man 1 passwd # passwd command # View all matching pages man -a printf # Show all printf manuals # View manual in specific language LANG=es_ES man ls

Display manual pages for commands and topics

Searching manual pages

# Search by keyword man -k network man -k "file system" # Search with apropos (same as -k) apropos copy apropos "regular expression" # Get short description man -f ls whatis ls # Same as man -f # Search in specific section man -k -s 1 copy

Search for manual pages by keywords and descriptions

Manual page information

# Show location of manual files man -w ls man --where passwd # Show path for specific section man -w 5 passwd # List all manual paths manpath # Update manual database sudo mandb

Get information about manual page locations and database

Navigating Manual Pages

Navigation Keys (in less pager)
  • Space or Page Down - Next page
  • b or Page Up - Previous page
  • or j - Next line
  • or k - Previous line
  • g - Go to beginning
  • G - Go to end
  • /pattern - Search forward
  • ?pattern - Search backward
  • n - Next search result
  • N - Previous search result
  • h - Help
  • q - Quit

Search within manual pages

# While viewing a manual page: /search_term # Search forward for "search_term" ?search_term # Search backward for "search_term" n # Go to next match N # Go to previous match # Case-insensitive search /(?i)pattern # Search ignoring case

Search for specific content within manual pages

Advanced Usage

Output formatting

# Generate HTML output man -H firefox ls # Generate PostScript for printing man -t ls | lpr # Save manual as text file man ls | col -b > ls_manual.txt # Use different pager man -P cat ls # Use cat instead of less man -P "less -S" ls # Use less with specific options

Format manual pages for different output methods

Configuration and customization

# Set default pager export PAGER=less export MANPAGER="less -X" # Set manual path export MANPATH=/usr/share/man:/usr/local/share/man # Configure less for better manual viewing export LESS="-R -M -I -j.5" # Set manual width export MANWIDTH=80

Customize manual page display and behavior

Batch operations

# Generate manual index sudo mandb # Find all manuals containing keyword man -k . | grep -i network # List all available manual pages man -k . | wc -l # Find manuals in specific section man -k . | grep "^.*([1-8])" # Export manual to different formats for cmd in ls cp mv; do man $cmd | col -b > ${cmd}_manual.txt done

Batch processing and management of manual pages

Manual Page Structure

Standard Sections
  • NAME - Command name and brief description
  • SYNOPSIS - Command syntax and options
  • DESCRIPTION - Detailed description of functionality
  • OPTIONS - Command-line options and arguments
  • EXAMPLES - Usage examples
  • FILES - Related files and directories
  • SEE ALSO - Related commands and references
  • BUGS - Known issues and limitations
  • AUTHOR - Author information

Reading manual syntax

# Understanding synopsis notation: command [OPTION]... FILE... # [] = optional # ... = can be repeated # | = alternatives (or) # {} = required group # Examples: ls [OPTION]... [FILE]... # ls with optional options and files cp [OPTION]... SOURCE DEST # cp requires source and destination grep [OPTION]... PATTERN [FILE]... # grep requires pattern

Understanding the syntax notation used in manual pages

Practical Examples

Learning new commands

# Discover commands for specific tasks man -k "copy files" man -k "text editor" man -k "network" # Learn about system calls man 2 open man 2 fork man 2 execve # Understand file formats man 5 fstab man 5 passwd man 5 crontab

Use man to learn about new commands and system concepts

Quick reference

# Quick command lookup whatis tar whatis grep whatis awk # Find commands by functionality apropos compress apropos "regular expression" apropos archive # Get command location and manual which ls && man ls type -a python && man python

Quick reference and command discovery

Documentation workflow

# Create personal command reference mkdir ~/manuals man ls | col -b > ~/manuals/ls.txt man grep | col -b > ~/manuals/grep.txt # Search across multiple manuals grep -r "regular expression" ~/manuals/ # Create command cheat sheet echo "# Common Commands" > cheatsheet.md for cmd in ls grep find; do echo "## $cmd" >> cheatsheet.md man $cmd | col -b | head -20 >> cheatsheet.md done

Building personal documentation and reference materials

Troubleshooting

Common Issues
  • No manual entry - Command not installed or no manual available
  • Broken display - Terminal encoding or pager issues
  • Missing sections - Development packages not installed
  • Outdated cache - Manual database needs updating

Fixing manual issues

# Update manual database sudo mandb # Check manual paths manpath echo $MANPATH # Install missing manual pages sudo apt install man-db manpages-dev # Debian/Ubuntu sudo yum install man-pages man-pages-devel # RHEL/CentOS # Fix encoding issues export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 # Reset pager settings unset PAGER MANPAGER

Resolve common manual page display and access issues

Alternative documentation

# Use info pages info ls info grep # Built-in help ls --help grep --help # Online documentation curl cheat.sh/ls curl cht.sh/grep # Local documentation ls /usr/share/doc/ find /usr/share/doc -name "*.txt" -o -name "README*"

Alternative sources of command documentation

See also