A Drush 9 list of commands (for Drupal 8)

I’m sure there’s something I’m missing here, but ... as I’m just getting started using Drush 9 to manage a Drupal 8 website, I can’t find a list of Drush 9 commands on the drush.org website. Therefore, in an effort to make my life easier (and hopefully yours), here’s a list of Drush 9 commands.

Please note that you can get this list by typing drush at your command line after you’ve installed Drush, but for me it’s easier to read these online, so I can easily scan them and also refer to them when I’m doing other things in my console/terminal window.

Drush 9 commands

Here are the available Drush 9 commands:

Drush Commandline Tool 9.2.1

Run `drush help [command]` to view command-specific help.
Run `drush topic` to read even more documentation.

Available commands:
 _global:
   help                                       Display usage details for a command.
   list                                       List available commands.
   generate (gen)                             Generate boilerplate code for modules/plugins/services etc.
   version                                    Show Drush version.
   runserver (rs, serve)                      Runs PHP's built-in http server for development.
   browse                                     Display a link to a given path or open link in a browser.
   updatedb (updb)                            Apply any database updates required (as with running update.php).
   updatedb:status (updbst)                   List any pending database updates.
   drupal:directory (dd)                      Return the filesystem path for modules/themes and other key folders.
   twig:compile (twigc)                       Compile all Twig template(s).
cache:                                                                                                                             
   cache:get (cg)                             Fetch a cached object and display it.
   cache:clear (cc)                           Clear a specific cache, or all Drupal caches.
   cache:set (cs)                             Cache an object expressed in JSON or var_export() format.
   cache:rebuild (cr, rebuild)                Rebuild a Drupal 8 site.
config:                                                              
   config:pull (cpull)                        Export and transfer config from one environment to another.
   config:get (cget)                          Display a config value, or a whole configuration object.
   config:set (cset)                          Set config value directly. Does not perform a config import.
   config:edit (cedit)                        Open a config file in a text editor. Edits are imported after closing editor.
   config:delete (cdel)                       Delete a configuration key, or a whole object.
   config:status (cst)                        Display status of configuration (differences between the filesystem configuration and 
                                              database configuration).
   config:export (cex)                        Export Drupal configuration to a directory.
   config:import (cim)                        Import config from a config directory.
core:                                                
   core:rsync (rsync)                         Rsync Drupal code or files to/from another server using ssh.
   core:status (status, st)                   An overview of the environment - Drush and Drupal.
   core:topic (topic)                         Read detailed documentation on a given topic.
   core:edit (conf, config)                   Edit drushrc, site alias, and Drupal settings.php files.
   core:execute (exec, execute)               Execute a shell command. Usually used with a site alias.
   core:init (init)                           Enrich the bash startup file with bash aliases and a smart command prompt.
   core:cron (cron)                           Run all cron hooks in all active modules for specified site.
   core:requirements (status-report, rq)      Information about things that may be wrong in your Drupal installation.
entity:               
   entity:updates (entup)                     Apply pending entity schema updates.
   entity:delete (edel)                       Delete content entities.
image:                                                              
   image:flush (if)                           Flush all derived images for a given style.
   image:derive (id)                          Create an image derivative.
locale:                                                           
   locale:check                               Checks for available translation updates.
   locale:update                              Imports the available translation updates.
php:                                            
   php:eval (eval, ev)                        Evaluate arbitrary php code after bootstrapping Drupal (if available).
   php:script (scr)                           Run php a script after a full Drupal bootstrap.
   php:cli (php, core:cli, core-cli)          Open an interactive shell on a Drupal site.
pm:                                           
   pm:security (sec)                          Check Drupal Composer packages for pending security updates.
   pm:enable (en)                             Enable one or more modules.
   pm:uninstall (pmu)                         Uninstall one or more modules and their dependent modules.
   pm:list (pml)                              Show a list of available extensions (modules and themes).
queue:
   queue:run                                  Run a specific queue by name.
   queue:list                                 Returns a list of all defined queues.
   queue:delete                               Delete all items in a specific queue.
role:
   role:create (rcrt)                         Create a new role.
   role:delete (rdel)                         Delete a new role.
   role:perm:add (rap, role-add-perm)         Grant specified permission(s) to a role.
   role:perm:remove (rmp, role-remove-perm)   Remove specified permission(s) from a role.
   role:list (rls)                            Display a list of all roles defined on the system.
site:
   site:set (use)                             Set a site alias that will persist for the current session.
   site:alias (sa)                            Show site alias details, or a list of available site aliases.
   site:alias-convert (sa-convert, sac)       Convert legacy site alias files to the new yml format.
   site:ssh (ssh)                             Connect to a Drupal site's server via SSH.
   site:install (si, sin)                     Install Drupal along with modules/themes/configuration/profile.
sql:
   sql:connect                                A string for connecting to the DB.
   sql:create                                 Create a database.
   sql:drop                                   Drop all tables in a given database.
   sql:cli (sqlc)                             Open a SQL command-line interface using Drupal's credentials.
   sql:query (sqlq)                           Execute a query against a database.
   sql:dump                                   Exports the Drupal DB as SQL using mysqldump or equivalent.
   sql:sync                                   Copy DB data from a source site to a target site. Transfers data via rsync.
   sql:sanitize (sqlsan)                      Sanitize the database by removing or obfuscating user data.
state:
   state:get (sget)                           Display a state value.
   state:set (sset)                           Set a state value.
   state:delete (sdel)                        Delete a state entry.
theme:
   theme:enable (then)                        Enable one or more themes.
   theme:uninstall (thun)                     Uninstall theme.
user:
   user:login (uli)                           Display a one time login link for user ID 1, or another user.
   user:information (uinf)                    Print information about the specified user(s).
   user:block (ublk)                          Block the specified user(s).
   user:unblock (uublk)                       UnBlock the specified user(s).
   user:role:add (urol, user-add-role)        Add a role to the specified user accounts.
   user:role:remove (urrol, user-remove-role) Remove a role from the specified user accounts.
   user:create (ucrt)                         Create a user account.
   user:cancel (ucan)                         Cancel user account(s) with the specified name(s).
   user:password (upwd)                       Set the password for the user account with the specified name.
views:
   views:dev (vd)                             Set several Views settings to more developer-oriented values.
   views:list (vl)                            Get a list of all views in the system.
   views:execute (vex)                        Execute a view and show a count of the results, or the rendered HTML.
   views:analyze (va)                         Get a list of all Views and analyze warnings.
   views:enable (ven)                         Enable the specified views.
   views:disable (vdis)                       Disable the specified views.
watchdog:
   watchdog:show (wd-show, ws)                Show watchdog messages.
   watchdog:list (wd-list)                    Interactively filter the watchdog message listing.
   watchdog:delete (wd-del, wd-delete, wd)    Delete watchdog log records.
   watchdog:show-one (wd-one)                 Show one log record by ID.

As a brief note, you can use the Drush command abbreviations like this:

$ drush sec

That command checks to see if there are any security updates available. Output from that command looks like this:

[success] There are no outstanding security updates for Drupal projects.

Note: On April 21, 2018, I found that output to be wrong. There is a Drupal security update (8.5.2), and this command did not report it properly.

Getting a list of available updates with Drush 9

With Drush 9 it looks like the trusty old drush ups command is no longer available. Unfortunately it looks like the only replacement available at this time is to use this command:

$ composer outdated

and it has a very different output than the drush ups command I used with Drush 8.

I’m a newbie here, but a problem with this is that it’s hard to tell if there’s a Drupal update available that’s not a security update. For instance, right now I’m running Drupal 8.4.5 and I can see from the Drupal web interface that Drupal 8.5.0 is available, but I can’t see that same output from the command line.

Update: As of this writing, from this discussion on Github it currently looks like the previous Drush pm-update and pm-updatestatus commands are no longer available (until they can find someone interested in recreating them for Drush 9).

Drush 9 command details

Again, I’m probably missing something, but as of this writing on March 27, 2018, I also can’t find detailed Drush 9 command information online. For example, if you search for cache:clear on that website you get “No results found.” Therefore, I want to use this as a reference page for the main Drush commands, after which I can get more details on the command line like this:

$ drush help cache:clear

Clear a specific cache, or all Drupal caches.

Arguments:
  type The particular cache to clear. Omit this argument to choose from available types. 

Options:
  --cache-clear[=CACHE-CLEAR] Set to 0 to suppress normal cache clearing; the caller should then clear if needed. [default: "true"] 
  --no-cache-clear            Negate --cache-clear option.                                                                          

Aliases: cc, cache-clear

As noted earlier, I created this list of Drush 9 commands by simply typing drush at the command line, and this was the output of that command.

How to update Drupal 8 core with Drush 9 and Composer

Per this drupal.org doc:

It’s recommended to use Composer to manage Drupal dependencies; read Using Composer with Drupal for more information. Drush 9 no longer supports updating Drupal and leaves the work to Composer. Hence it is recommended to use Composer to update Drupal. However, if you are a long-time Drush user, you may still use Drush 8 (8.14 or newer) to update Drupal 8.

Per the second link in that paragraph it looks like the commands to update Drupal 8 core with Drush 9 are:

composer update drupal/core --with-dependencies
drush updatedb
drush cr

IMPORTANT: Note that they write, “If the composer command doesn't work, check the current recommended update command from drupal-composer/drupal-project.”

As a final note in this section, you can still update Drupal 8 manually, as described in this drupal.org doc.

Installing Drush 9

As a final note, if you need to install Drush 9, you have to first install Composer, and then install Drush 9. I installed Composer by following the instructions on their download page. I then installed Drush 9 with this command:

$ composer require drush/drush

These links were helpful in understand the Composer/Drush installation process:

In summary, if you wanted to see a list of the available Drush 9 commands, I hope this is helpful.