Dru(pal)sh(ell) is an essential tool if you are working with Drupal intensively. If you don't know it yet, Drush is command line shell and scripting interface for Drupal. It helps you to quickly perform various administation and maintenance tasks using only a terminal. If you are not convinced, you should probably install it and give it a try. You won't regret it. It's awesome and will save you headaches, time and again more time. If you are using Drush, you must have been using the command "drush cc all" like a million time. I have. But Drush can do much more.
This is neither a tutorial on how to use Drush, nor an exhaustive list of commands. It's more a limited list of commands that we use on a daily basis or that have save our days. If you use Drush, let us know your best tricks and tips.
# Provide a one-time login for the root user drush uli # Provide a one-time login for a particular user based on the UID or mail drush uli 2 drush ul email@example.com
# Tail the watchdog log in your terminal drush ws --tail
Feature is sometimes a bit clumsy, but is a must have if you are serious about deployments. Unfortunately, the GUI becomes unusable on large website. Drush comes to the rescue, and will give you the power to easily revert, update or add extra components to your existing features.
# List all the components drush fc drush fc --not-exported # Add a new component to an existing feature drush fe component:name modulename # List all features drush fl # Update a feature (database to code) drush fu feature-name # Update all feature without prompting for confirmation drush fua -y # Revert a feature (code to database) drush fr feature-name # Revert all feature without prompting for confirmation drush fra - y
# Download a module drush dl module-name # Download module for a specific release drush dl module-name-7.x-2.0 drush dl module-name-7.x-2.0 --destination=site/..... # Search if a module exist and its status. drush pml --no-core | grep module-name # Enable/disable/uninstall a module drush en module-name drush dis module-name drush pm-uninstall module-name # Reinstall a module [Require the devel module] drush devel-reinstall module-name
# Flush cache with prompt drush cc # Flush all cache drush cc all # Flush image preset drush image-flush
# Run cron drush cron
# Check if any updates are available drush up -n | grep available # Update DB (similar to /update.php) drush updb # Update core and DB drush upc # Backup db + update contrib drush up
# Set/get/delete a variable drush vget variable-name drush vset variable-name variable-value drush vdel variable-name # Particularly useful if you got a "white screen of death" (WSOD) drush vset theme.default themename drush vset admin.theme themename
# Archive the code, db and asset in a single file drush ard --destination=/var/www/site/backups/example.tar # Dump, Drop or import the DB drush sql-dump > mydb.sql drush sql-drop drush sql-cli < mydb.sql # Connect to mysql drush sqlc
Hope you found those commands useful. Feel free to share your best tricks and tip with us.