Command-line tools & useful commands for Drupal developers

lakshmi , Credit to  volkotech-solutions Jun 07

Drush, Composer and Drupal Console are CLI tools for Drupal, providing interaction with the site and code generation. All three can be installed via Composer.

Drush is Drupal's first CLI, Composer is a popular PHP dependency management tool, and Drupal Console uses the Symfony Console library.

Drush commands:

Drush command Description Examples
$drush cr Used to Cache rebuild. $drush cr
$drush en module-name Used to enable the module in drupal $drush en devel
$drush pm:list Displays a list of extensions that are available (modules and themes). $drush pm:list
$drush generate-content Select any available generator and run it. for example devel $drush devel-generate:content
$drush pm:uninstall module-name Used to uninstall the module in drupal $drush pm:uninstall devel
$drush views:list Displays a list of all Views available on the Drupal site. $drush views:list
$drush core:status Displays an overview of the Drupal environment $drush core:status
$drush pm:security Checks for pending security updates in Drupal Composer packages. $drush pm:security
$drush updatedb Used to run any pending database updates. $drush updatedb
$drush ib Used to import custom blocks. $drush ib
$drush ea Used to export all of the above (menus,  terms, and blocks). $drush ea
$drush et Used to export taxonomy terms. $drush et
$drush em Used to export custom menus. $drush em
$drush eb Used to export custom blocks. $drush eb
$drush ia for importing all of the above menus, terms, and blocks). $drush ia
$drush it Used to import taxonomy terms. $drush it
$drush im Used to importing custom menus. $drush im

Composer commands:

Composer commands Description Examples
$composer list Displays a list of all available commands. $composer list
$composer require drupal/modulename Used to download a Drupal module. $composer require drupal/admin_toolbar
$composer update drupal/modulename --with-dependencies Update Drupal modules with their dependencies $composer update drupal/admin_toolbar --with-dependencies
$composer install To install a module based on composer.json $composer install
$composer update Updates composer.json $composer update
$composer init In the current directory, produces a basic composer.json file $composer init
$composer create-project Creates a new project from a package. $composer create-project drupal-composer/drupal-project:8.x-dev drupal8 --stability dev --no-interaction
$composer self-update Updates composer.phar to the latest version. $composer self-update
$composer clearcache Clears the composer's internal package cache. $composer clearcache
$composer exec Executes a vendored binary/script. $composer exec

Drupal console commands:

Drupal Console Commands Description Examples
$drupal cr all All caches on the website should be rebuilt and cleared. $drupal cr all
$drupal generate:module Generate a drupal module. $drupal generate:module
$drupal generate:entity:content Create a new content entity. $drupal generate:entity:content
$drupal generate:form Generate a new FormBase for the drupal module. $drupal generate:form
$drupal generate:controller Generate a new controller for the drupal module. $drupal generate:controller
$drupal config:export:content:type A specified content type and its fields can be exported. $drupal config:export:content:type
$drupal generate:theme Generate a custom theme. $drupal generate:theme
$drupal taxonomy:term:delete Taxonomic terms should be deleted from a vocabulary list. $drupal taxonomy:term:delete
$drupal user:role
 

Adds or removes a role for a certain user.

$drupal user:role

To learn about git commands click here.

Conclusion:

Dush, Composer, and Drupal Console is a tool that aids in the development of Drupal applications. These command-line tools allow users to interact with a Drupal site easily by using commands.

Comments