Upgrade Your Drupal Skills
We trained 1,000+ Drupal Developers over the last decade.
See Advanced Courses NAH, I know EnoughEasy 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:
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
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:
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:
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:
- Running the
drush
ordrupal
command will return the full list of available commands and a brief description of how to use each one - Add the pipe (
|
) after thedrush
ordrupal
command will connect a second command - Adding grep and the keyword after the pipe will result in the output of the
drush
ordrupal
command being passed as input to the second commandgrep
. In other words, it will search for the keyword in the full list and return just those lines that match the keyword
About Drupal Sun
Drupal Sun is an Evolving Web project. It allows you to:
- Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
- Facet based on tags, author, or feed
- Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
- View the entire article text inline, or in the context of the site where it was created
See the blog post at Evolving Web