Understanding Shell Commands Easily Using “Explain Shell” Script in Linux

While working on Linux platform all of us need help on shell commands, at some point of time. Although inbuilt help like man pages, whatis command is helpful, but man pages output are too lengthy and until and unless one has some experience with Linux, it is very difficult to get any help from massive man pages. The output of whatis command is rarely more than one line which is not sufficient for newbies.

Explain Shell Commands in Linux Shell
Explain Shell Commands in Linux Shell

There are third-party application like ‘cheat‘, which we have covered here “Commandline Cheat Sheet for Linux Users. Although Cheat is an exceptionally good application which shows help on shell command even when computer is not connected to Internet, it shows help on predefined commands only.

There is a small piece of code written by Jackson which is able to explain shell commands within the bash shell very effectively and guess what the best part is you don’t need to install any third party package. He named the file containing this piece of code as 'explain.sh'.

Features of Explain Utility

  1. Easy Code Embedding.
  2. No third-party utility needed to be installed.
  3. Output just enough information in course of explanation.
  4. Requires internet connection to work.
  5. Pure command-line utility.
  6. Able to explain most of the shell commands in bash shell.
  7. No root Account involvement required.

The only requirement is 'curl' package. In most of the today’s latest Linux distributions, curl package comes pre-installed, if not you can install it using package manager as shown below.

# apt-get install curl 	[On Debian systems]
# yum install curl 		[On CentOS systems]

Installation of explain.sh Utility in Linux

We have to insert the below piece of code as it is in the ~/.bashrc file. The code should be inserted for each user and each .bashrc file. It is suggested to insert the code to the user’s .bashrc file only and not in the .bashrc of root user.

Notice the first line of code that starts with hash (#) is optional and added just to differentiate rest of the codes of .bashrc.

# explain.sh marks the beginning of the codes, we are inserting in .bashrc file at the bottom of this file.

# explain.sh begins
explain () {
  if [ "$#" -eq 0 ]; then
    while read  -p "Command: " cmd; do
      curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
    echo "Bye!"
  elif [ "$#" -eq 1 ]; then
    curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1"
    echo "Usage"
    echo "explain                  interactive mode."
    echo "explain 'cmd -o | ...'   one quoted command to explain it."

Working of explain.sh Utility

After inserting the code and saving it, you must logout of the current session and login back to make the changes taken into effect. Every thing is taken care of by the ‘curl’ command which transfer the input command and flag that need explanation to the mankier server and then print just necessary information to the Linux command-line. Not to mention to use this utility you must be connected to internet always.

Let’s test few examples of command which I don’t know the meaning with explain.sh script.

1. I forgot what ‘du -h‘ does. All I need to do is:

$ explain 'du -h'
Get Help on du Command
Get Help on du Command

2. If you forgot what ‘tar -zxvf‘ does, you may simply do:

$ explain 'tar -zxvf'
Tar Command Help
Tar Command Help

3. One of my friend often confuse the use of ‘whatis‘ and ‘whereis‘ command, so I advised him.

Go to Interactive Mode by simply typing explain command on the terminal.

$ explain

and then type the commands one after another to see what they do in one window, as:

Command: whatis
Command: whereis
Whatis Whereis Commands Help
Whatis Whereis Commands Help

To exit interactive mode he just need to do Ctrl + c.

4. You can ask to explain more than one command chained by pipeline.

$ explain 'ls -l | grep -i Desktop'
Get Help on Multiple Commands
Get Help on Multiple Commands

Similarly you can ask your shell to explain any shell command. All you need is a working Internet connection. The output is generated based upon the explanation needed from the server and hence the output result is not customizable.

For me this utility is really helpful and it has been honored being added to my .bashrc. Let me know what is your thought on this project? How it can useful for you? Is the explanation satisfactory?

Provide us with your valuable feedback in the comments below. Like and share us and help us get spread.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

13 thoughts on “Understanding Shell Commands Easily Using “Explain Shell” Script in Linux”

  1. looking for a person who has an idea how to do this:

    Create a bash-shell script called terminator that
    terminates all processes of a name given to the shell
    script as an argument.
    (Guidance: pidof, ps –ef , awk)

    if anyone has an idea please let me know :)

  2. This is a rather lame utility that gives you very, very little that you can’t get with the ‘man’ command. As the old saying goes, this is a utility that fills a much-needed gap in the Linux world.

  3. I had the same problem as @aligaligari
    I am using Ubuntu and in my man page for curl the “–data-ur” option is not listed (only “–data-urlencode”)
    However, I managed to run the explain command after changing the script as follows:

    # explain.sh begins
    explain () {
    if [ “$#” -eq 0 ]; then
    while read -p “Command: ” cmd; do
    # curl -Gs “https://www.mankier.com/api/explain/?cols=”$(tput cols)–data $
    curl -Gs “https://www.mankier.com/api/explain/?cols=70&q=”$cmd
    echo “Bye!”
    elif [ “$#” -eq 1 ]; then
    # curl -Gs “https://www.mankier.com/api/explain/?cols=”$(tput cols) –data-ur $
    curl -Gs “https://www.mankier.com/api/explain/?cols=70&q=”$1
    echo “Usage”
    echo “explain interactive mode.”
    echo “explain ‘cmd -o | …’ one quoted command to explain it.”

  4. :)…
    # explain ‘du -h’
    curl: option –data-ur-$: is unknown
    curl: try ‘curl –help’ or ‘curl –manual’ for more information

    What’s going on? :-/

    • @aligaligari,

      When i run the same command, here is what i get.
      [email protected]:~$ explain ‘du -h’

      Summarize disk usage of the set of FILEs, recursively for directories.
      Mandatory arguments to long options are mandatory for short options too.

      -h (-h, –human-readable)
      print sizes in human readable format (e.g., 1K 234M 2G)

      are you able to explain other shell command? Is the problem with this command only or every other command? Please check the code you pasted in your .bashrc file. Also let us know your distribution and release. If you are unable to resolve you may forward me SSH credentials at avishek1210[at]gmail.com

      • i get exact same thing when run the command:
        curl: option –data-ur$: is unknown
        curl: try ‘curl –help’ or ‘curl –manual’ for more information

        uname -a
        Linux valinux 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

        curl –version
        curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/ zlib/1.2.3 libidn/1.18 libssh2/1.4.2
        Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
        Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

        • Dear wally,
          The code has been fixed. Clear cache and Refresh page. Use the new code.
          If any issue let me know.

    • sorry for the inconvenience @aligaligari,
      There was a small error in the code which is fixed now.
      Please clear the cache, Refersh this page and use the code above.
      If any issue, don’t mind to ping me.


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.