4x Affordable, 99.95% SLA, 24x& Video Support, 100+ Countires

A Beginner's Guide For Drush The Drupal Shell

About Drush

Drush is an awesome shell interface for managing Drupal right from your cloud server command line. It is a very useful tool as it helps you perform various admin tasks using just one or two commands in the terminal, replacing the need for many clicks and page refreshes in the UI.

This tutorial will go through some of the basic Drush commands and work with a standard Drupal installation to illustrate them. It assumes then that you already have Drush installed on your cloud server and you have a working copy of Drupal on it. If you don't know how to do this, please refer to an earlier tutorial explaining all the steps.

Note: All the following commands need to be performed from within the directory of a Drupal installation. Doesn't really matter where you are located, as long as you are somewhere within the root folder.

To begin, first navigate your Drupal folder directory:

cd /var/www/[drupal_folder_name]

Some General Commands

One of the most simple Drush commands is:

drush status

This will give you an overview of your Drupal site. Version, URI, database location, file paths, default theme etc. If you use this command and you do not see this information, it means you are in a wrong folder and Drush does not know which Drupal site you are referring to.

If you are a Drupal developer, you know that flushing the cache is something you very often do. With Drush, it's almost fun to do it:

drush cc

This will ask you which kind of cache you want to delete for more granular control but if you run the following command, you will directly clear all the caches:

drush cc all

Drupal Projects

Let's install Views (I'm sure you know about this module). To do this, you first have to run the following command:

drush pm-download views
drush dl views

Either one of these commands will download Views and place it in the appropriate sites/all/modules folder. The second command is a short version of the first one. You'll notice that many commands have short versions for an even faster experience. For instance, the long version of the drush status command is drush core-status, so don't be surprised if you see others using that one.

Now that Views is installed, enable it with the following command (the long version of which being pm-enable):

drush en views

You'll see that Drush immediately tells you that Views requires Ctools to be downloaded and enabled and asks you if it should perform those actions as well. If you select yes, it will download Ctools and will ask you once more to confirm whether you want Views and Ctools to be enabled. Say yes again and it's done. Now, how many clicks and URL copies have you saved with just this one command?

If you want to disable Views, run the following command (the long version of which being pm-disable):

drush dis views

And if you are looking to uninstall Views, you can use the following command:

drush pm-uninstall views
This will also remove the database tables belonging to that module. Note: the module names you should use with Drush are the machine names. If you have doubts about what is that name, you can easily retrieve it from the module project page URL: drupal.org/project/views. The last URI segment is what you are looking for. Additionally, you can specify multiple module names separated by one space if you want Drush to perform the actions on all of them. For instance:
Reference: digitalocean