Skip to content
Home ยป Get Quick Answers with the Linux --help Flag & man-pages

Get Quick Answers with the Linux --help Flag & man-pages

  • Linux
  • 3 min read

When it comes to using Linux, it can sometimes be overwhelming trying to figure out how to do certain tasks. Luckily, there are a few resources that can help you navigate the command line and troubleshoot problems. In this blog, we’ll be discussing two of those resources: the man command and the --help flag.

Man Pages

The man command stands for “manual,” and it is used to display the manual pages for a command. For example, if you want to learn more about the ls command, you can type man ls and hit enter. This will bring up the manual page for ls, which includes a description of the command, a list of options and arguments that can be used with it, and some examples of how to use it.

Here’s an example of how to use the man command:

$ man ls

LS(1)                                                                                 
User Commands                                                                                 
LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

       Mandatory  arguments  to  long options are mandatory for short options too.

       -a, --all
              do not ignore entries starting with .

       -A, --almost-all
              do not list implied . and ..

[...]

As you can see, the man page for ls includes a lot of information about the command, including a description of what it does, a list of options and arguments that can be used with it, and some examples of how to use it.

The -help Flag

Another useful resource for getting help with Linux commands is the --help flag. This flag can be used with most commands to display a brief overview of the command and its options. For example, if you want to learn more about the cp command, you can type cp --help and hit enter. This will bring up a brief overview of the cp command and a list of options that can be used with it.

Here’s an example of how to use the --help flag:

$ cp --help
Usage: cp [OPTION]... [-T] SOURCE DEST
  or:  cp [OPTION]... SOURCE... DIRECTORY
  or:  cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
  -a, --archive                same as -dR --preserve=all
  -b, --backup[=CONTROL]       make a backup of each existing destination file
  -d                           same as --no-dereference --preserve=links
  -f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again (this option
                                 is ignored when the -n option is also used)
  -i, --interactive            prompt before overwrite (overrides a previous -n
                                 option)
  -H                           follow command-line symbolic links in SOURCE
  -l, --link                   hard link

Examples

# Show manual page for the 'ls' command
man ls

# Show manual page for a specific section of the 'grep' command
man 2 grep

# Show manual page for the 'sed' command in a less pager
man sed | less

# Search for a specific keyword in the 'awk' command manual page
man awk | grep -i 'pattern'

# Show the manual page for a specific version of 'gcc' command
man -s 7 gcc

# show the manual page for a command and save it to a file
man -t ls > ls_manual.pdf

Leave a Reply

Your email address will not be published. Required fields are marked *

15 − 10 =