How to get help in Bash
There two commands for you to get help in the Bash. They are help and the man command.
But you need to know the command you want to use in order to get help on it.
help
Let’s say you want to help with cd command. So in your Bash shell type
help cd
Now what you need to focus on is the first line. in this case, it is
so this is the command itself and all the optional parameters it has in order to use it. So anything inside the square bracket is optional, and anything that is divided by a vertical bar, or usually we call by pipe symbol “|” meaning it’s mutually exclusive, which means you can use only one of the options but not both.
For example, you can use
cd -L -e /path/to/directory
cd -P -e /path/to/directory
but not
L -P -e /path/to/directory
Now you u have thought of what does this -L, -P really means. So those are listed in the options section.
So to make the most use of this command you need to scan the top section of the command and then the options section. both I described earlier. See the sections highlighted in yellow.
also if you are in the middle of a command and you realize that you need some help with the command, you can call help by adding “ — help” to the end of the command. refer to the below example
Now what if help isn’t given much help, then you can use the man command.
man
here is how man cd works.
one thing to note is this assumes you are in a terminal with no mouse, so scrolling may work but don’t rely on that. Because now you are inside an actual text file and not in a shell anymore. so to get help on how to navigate inside this text file hit the h key.
to navigate
half page up -> u
half page down -> d
move full page -> space
to move a single line up -> k
to move a single line down -> j
to exit from navigate help -> q
Now man gives a very detailed explanation of how exactly the command works.
What you need to look out for is the NAME and the SYNOPSIS sections.
after that typically you need to find the EXAMPLES section. to do that you need to type forward slash “/” and “examples”.
and you will immediately find examples like those below.
In summary, you look at the synopsis, and different options that come with it then come down for the actual examples.
once you are done with the man pages hit q to exit.
Credits:
The article “How to Get Help in Bash” draws inspiration from and references the following YouTube video:
- Video Title: “How to Get Help in Bash [4 of 20] | Bash for Beginners”
- YouTube Link: Watch Here
Original Video Creators:
I would like to express my gratitude to Josh Duffney and Gwyneth Peña-Siguenza for creating the informative and helpful video that served as a valuable resource in the development of this article.