n Useful Drush commands in Drupal 8 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh


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


Example: how to generate custom config entity

vendor/bin/drush generate module-configuration-entity  

Example: how to get/set config values

get uuid with drush:

vendor\bin\drush config-get "system.site" uuid

change uuid with drush:

vendor\bin\drush cset system.site uuid YOUR_UUID -y

Example: update user password



drush upwd root MyPass0302oplm

Example: Export Drupal 8 MySQL Database via Drush

drush  sql-dump --result-file=/pathto/mysql-dump-drupal8.sql

Example: Export Drupal 8 MySQL Database via Drush to a gz compressed file

drush sql-dump  --gzip --result-file=/pathto/mysql-dump-drupal8.sql.gz

Example: Import Drupal 8 and MySQL Database via Drush

drush sql-drop
drush sql-cli
mysql> source /pathto/mysql-dump-drupal8.sql

Example: Import a GZ compressed file

drush sql-drop --yes
gzip -dc /pathto/mysql-dump-drupal8.sql | drush sql-cli


Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts


Page Facebook