The type, help and man Commands
Think of help and man as your built-in Linux cheat sheets. When you're not sure how to use a command or need to look up its options, these commands are your best friends. They're like having a Linux expert right at your fingertips!
Quick Reference
| Command | Description | Common Use |
|---|---|---|
type |
Show what kind of command something is | Debugging, understanding commands |
help |
Show help for built-in shell commands only | Quick reference for commands like cd, echo, pwd |
man |
Show detailed manual pages for non-built-in commands | Complete documentation for commands like ls, grep, cat |
type Command
There are four types of commands in Linux: built-in, alias, function, and program.
| Type | Description | Example |
|---|---|---|
| Program | A program installed on your computer | grep |
| Built-in | A command that is built into the shell | cd |
| Alias | A shortcut for a command | ls is an alias for ls --color=auto |
| Function | A function in the shell | mkcd is a function that creates a directory and changes to it |
When you are not sure what a command is, you can use the type command to find out. For example, if you are not sure what ls is, you can use the type command to find out. The reason is due to the help files as help is only available for built-in commands and man is only available for non-built-in commands.
To check if a command is built into the shell, you can use type:
# Check if cd is a built-in command
type cd
# Output: cd is a shell builtin
# Check if ls is a built-in command
type ls
# Output: ls is /bin/ls # This means it's not built-in
help Command
The help command is like a quick reference guide for built-in shell commands. It's perfect when you need a fast reminder of how to use commands like cd, echo, or pwd.
Common Options
| Option | What It Does | When to Use It |
|---|---|---|
-d |
Show brief description | When you just need a quick summary |
-m |
Show man-page style format | When you want more detailed help |
-s |
Show short usage summary | When you just need the basic syntax |
Practical Examples
Basic Usage
# Get help for cd command
help cd
# Get brief description
help -d echo
# Get usage summary
help -s pwd
Sample Output (for help cd)
# help cd output
cd: cd [-L|[-P [-e]] [-@]] [dir]
Change the shell working directory.
Options:
-L force symbolic links to be followed
-P use the physical directory structure
-e if the -P option is supplied, and the current working directory
cannot be determined successfully, exit with a non-zero status
-@ on systems that support it, present a file with extended attributes
as a directory containing the attributes
man Command
The man command is like having a complete Linux manual at your fingertips. It provides detailed documentation for almost any command, including examples, options, and related commands.
When to Use man
Use man when you want to:
- Get complete documentation for a command
- See detailed examples and options
- Learn about related commands
- Understand command behavior in depth
- Find information about file formats or system calls
Common Options
| Option | What It Does | When to Use It |
|---|---|---|
-k |
Search for keywords | When you're not sure which command to use |
-f |
Show brief description | When you need a quick summary |
-a |
Show all matching pages | When a command has multiple manual pages |
-w |
Show file location | When you need to know where the man page is stored |
-K |
Performs a full-text search inside the actual man page contents. | When you need to find text across all manuals |
-k |
Runs a keyword search through the man page database. | When you need to find a specific keyword |
-l |
List manual pages | When you want to see all available man pages |
-P |
Use specific pager | When you want to use a different viewer |
Understanding Man Page Sections
Man pages are organized into numbered sections, each covering a different type of documentation. Not all commands will have pages in all sections - some might only appear in one section, while others (like passwd) might appear in multiple sections with different meanings.
| Section | What It Contains | Example | Notes |
|---|---|---|---|
| 1 | User commands | man 1 ls |
Most common section for everyday commands |
| 2 | System calls | man 2 open |
Functions provided by the kernel |
| 3 | Library functions | man 3 printf |
Programming library functions |
| 4 | Special files | man 4 null |
Device files in /dev |
| 5 | File formats | man 5 passwd |
Configuration file formats |
| 6 | Games | man 6 fortune |
Games and amusements |
| 7 | Miscellaneous | man 7 ascii |
Various topics and conventions |
| 8 | System admin | man 8 shutdown |
Commands for system administration |
How to Check Available Sections
To see which sections a command appears in, use the -f option:
# Check all sections for passwd
man -f passwd
# Output might show:
# passwd (1) - change user password
# passwd (5) - password file
Practical Examples
Basic Usage
# View manual for ls command
man ls
# Search for commands about files
man -k file
# View specific section
man 1 passwd
# Search all man pages for a term
man -K "regular expression"
# List all man pages
man -l
Navigation Tips
| Key | What It Does | When to Use It |
|---|---|---|
Space or f |
Move forward one page | When you want to read more |
b |
Move back one page | When you want to review previous content |
/pattern |
Search for text | When you're looking for specific information |
n |
Find next match | When you want to see more search results |
N |
Find previous match | When you want to go back to previous search results |
q |
Quit man page | When you're done reading |
h |
Show help | When you need to see all navigation options |
g |
Go to start | When you want to return to the beginning |
G |
Go to end | When you want to jump to the end |
Tips for Success
- Start with help: Use
helpfor built-in commands first - Use man for details: When you need complete documentation
- Try -k for discovery: Great for finding related commands
- Learn the navigation: Practice using man page navigation keys
Common Mistakes to Avoid
- Using
helpfor non-built-in commands - Forgetting to use
qto quit man pages - Not checking multiple sections when a command exists in more than one
- Not using
-kwhen you're not sure which command to use
Best Practices
- Use
helpfor quick reference of built-in commands - Use
manfor complete documentation - Learn the man page navigation shortcuts
- Use
-kto discover new commands