Explain Shell

Explain Shell

6th February 2022 - 5 minutes read time

If you are working on the Linux command line then sometimes you'll do a search to find out how to run a command that performs a task. I don't usually copy and paste commands in unless I can see what is going on, which used to mean spending time going through man pages and documentation trying to find out what this or that flag does.

That all changed when I found explainshell.com, which will extract the parameters of a command and tell you all about what the different flags will do.

A screenshot of the explainshell.com homepage

Since discovering this site I always paste in a command I found on the internet to see what it's doing, and the results are usually pretty good. It even understands pipes and output redirection and so will be able to split apart some of the more complex Linux commands into parts.

The tool also links out to the man pages used to generate the documentation so you can go back to the source to see the original command docs if you require.

There are some limitations to the tool. It is intended to document commands and will not tell you exactly what the command will do when run. You should be able to see what the command is doing based on the output of the tool, but if you are ever in any doubt about a command then pasting it into explainshell.com is always a good idea as a first pass.

The great think about the site is that every time you use the tool it updates the URL with parameters, which means you can share the results of your explain with other users. Quite handy if you want to link your documentation to something that documents what a command does.

To demonstrate the tool in action I have collected together a few commands from around this site and linked them to explainshell.com to show what they are doing.

This command lists all of the files in a directory by size.

du -hs * | sort -h

This will issue a standard GET request using curl to this site and show the redirects involved and the ultimate response from the final page. This shows a http to https redirect in action.

curl -sSLIXG http://www.hashbangcode.com

The curl command can also accept the G as the full word GET and sill run the command correctly. This though, confuses explainshell.com, which is understandable.

The following find command will go through all PHP files under the current path and will replace all old style short tags "<?" with the usual "<?php" tags. Whilst not the most robust of find and replace commands, it shows how to use the tool.

find . -name '*.php' -exec sed -ie 's#<?#<?php#' {} \;

Speaking of finding content, the following grep will search through all files under the current directory for the string containing @ViewsFilter("user and show three lines before and after each line of the result.

grep "@ViewsFilter(\"user" -r core -C 3

Lots of command line tools are also understood my explainshell.com. For example, you can type in any git command and see the full breakdown of the different flags involved.

git log --oneline --decorate --graph --all

Many thanks to Idan Kamara for creating such a neat tool, and for open sourcing the tool as well!

Add new comment

The content of this field is kept private and will not be shown publicly.