Blair Wadman 3 minute read

Easy way to find the Drush command you are looking for

Both Drush and Console have built-in help. If you type drush, you will get a long list of available commands. If you type drupal, again you will get a long list of available console commands. If you can’t remember the exact command to use to do what you need, you can scroll through the long list of commands to find the one you want.

But scrolling through the long list can be a real pain. Wouldn’t it be easier to see commands that relate to a particular activity without all the other commands in the same list?

Target the Drush or Console commands by keyword

Fortunately you can isolate what you need by adding the grep command to the drush or drupal console command, along with a pipe (|). This will allow you to filter the results by a keyword.

Here are a couple of examples.

Show watchdog Drush commands

You can use the Drush watchdog command to list messages in the database log, delete records and more.

drush | grep watchdog

This will return the following watchdog commands:

Drush grep watchdog

Show theme related Drupal console commands

You can use Drupal console to generate a new theme, download a theme, uninstall a theme and more.

drupal | grep theme

This will return the following

drupal grep theme

As you can see, this is a list of Drupal console theme commands.

Show generate console commands

Drupal console comes with a set of generate commands that you can use to generate the module controller, routes, menus and blocks for a custom module.

drupal | grep generate

This will return the following list of generate commands:

drupal grep generate

There are more generate commands than the above graphic. You can filter this down even further by making your search more specific. For example, if you need to generate a new plugin, you can search for generate:plugin with:

drupal | grep generate:plugin

This will return the following list of generate commands:

drupal grep generate plugin

The solution explained

What is grep?

Grep is a Unix command that will search and match based on a particular criteria.

What is pipe?

The pipe command allows you to connect commands together. The output from the first command will be passed through the second command.

This means that the following: