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.
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
- Easy Code Embedding.
- No third-party utility needed to be installed.
- Output just enough information in course of explanation.
- Requires internet connection to work.
- Pure command-line utility.
- Able to explain most of the shell commands in bash shell.
- No root Account involvement required.
Prerequisite
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" done echo "Bye!" elif [ "$#" -eq 1 ]; then curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1" else echo "Usage" echo "explain interactive mode." echo "explain 'cmd -o | ...' one quoted command to explain it." fi }
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'
2. If you forgot what ‘tar -zxvf‘ does, you may simply do:
$ explain 'tar -zxvf'
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
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'
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.
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 :)
How would that shell script be different than killall?
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.
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
done
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
else
echo “Usage”
echo “explain interactive mode.”
echo “explain ‘cmd -o | …’ one quoted command to explain it.”
fi
}
Same problem that @aligaligari. (hard to write :p )
I have tried with other commands but the problem is still here.
I use Ubuntu 15.04.
Dear Shad,
The issue in the code has been fixed. Please use the new code after refreshing the page.
Exactly the same result as aligaligari in both Debian Jessie and Sid. Whatever the command.
Sorry for the inconvenience @ Paco
the code is fixed. Use the new updated code.
:)…
# 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.
avi@deb:~$ explain ‘du -h’
du(1)
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
env:
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/3.14.3.0 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.