blog-banner

The Most Frequently Used Drush Commands

    Drush Commands Cheat Sheet

     

    If you are into Drupal development and a vivid user of GNU/ Linux (or *nix) for a while, then Drush is a must-learn tool for you. As a part of the Drupal development project, we extensively use Drush. A few commands that help us develop sites at the phase of the client's expectation are briefed below,

    1. drush cc [type]:- Clears a specific cache or all Drupal caches.

    Example

    $ drush cc all

    or if you want to rebuild only the menu
    $ drush cc menu

     

    2. drush sql-sync:- Copy and import source database to target database. Transfers via rsync

    Example

    $ drush sql-sync @dev.mysite @local.mysite
    Note: use --no-ordered-dump to make the restore faster. Also check levelten's blog, if you wish to know the configurations needed for this.
     

     

    3. drush sql-dump:- Exports the Drupal DB as SQL using mysqldump

    Example

    $ drush sql-dump > /path/to/backup_dir/database-backup.sql

     

    4. drush sql-connect:- Gives string for connecting to DB

    Example

    $ drush sql-connect
    To get directly dropped into the MySQL prompt use
    $ `drush sql-connect`
     
    5. drush rsycn:- Rsync the Drupal tree to/from another server using ssh

    Example

    To rsync the entire site

    $ drush rsync @dev @stage
    To rsync ony the files folder
    $ drush rsync @dev:%files @stage:%files
     
    6. drush pm-list:- Lists the complete set of modules installed in the site.
     
    Example

    $ drush pm-list

     
    7. drush dl module-name:-  Download the latest recommended release of Drupal core, specified module or theme.
     
    Example
    $ drush dl views
     
    8. drush en/dis - Enable or disables a drupal module.
     
    Example
    $ drush dis overlay
    Disable overlay module
    $ drush en -y views
    Using -y will make automatically download & enable the dependencies as well.
     
     
    9. drush scr:- Executes PHP files.
     
    Example
    $ drush scr filename.php
    Provides the drupal environment in the script runtime. Ideal for testing a snippet of module code.
     

    10. drush features-list:- List all the available features for your site.

    Example

    $ drush features-list
     
    11. drush features-revert:- Reverts the specific features
     
    Example
    $ drush features-revert frontpage
     
    12. drush sql-drop:- Drops all the tables in the given database
     
    Example
    $ drush sql-drop
    Output
    Do you really want to drop all tables(y/n) :
     
    13. drush status:- Provides all the details about the site.
    Drupal version         : 7.12
    Site URI               : http://default                              
    Database driver        : mysql
    Database hostname      : localhost
    Database username      : root
    Database name          : example
    Database               : Connected
    Drupal bootstrap       : Successful
    Drupal user            : Anonymous
    Default theme          : custom
    Administration theme   : seven
    PHP configuration      : /etc/php5/cli/php.ini
    Drush version          : 4.5
    Drush configuration    :
    Drush alias files      : /home/user/.drush/example.alias.drushrc.php
    Drupal root            : /home/user/Public/project
    Site path              : sites/default
    File directory path    : sites/default/files

    14. drush cron:- Triggers drupal cron run.

    Example

    $ drush cron
    Output
    Cron run successfully.                                                               [success]