How to enable multiple Drupal themes using the bash command line?

| | 3 min read

The default method of changing a Drupal theme using the graphical Admin interface is familiar to most Drupal users. However a Drupal user is limited to changing only one theme at a time using this method and it is also slightly time consuming. What if you want to enable more then one theme at a time? Drupal provides a quicker way to change the theme using the bash command line. Read on to know how to enable multiple Drupal themes using the bash command line

  1. First we have to install drush on your server. Drush is a command line interface for accessing and working with Drupal
  2. After installing Drush lets check out all the existing themes in our Drupal site
  3. Type the following command from your Drupal server
    ~/drush/drush pm-list --type=theme
  4. In sites/all/themes folder type
    drush pm-list --type=theme
  5. This will display all themes in following order
    • Package
    • Name
    • Status
    • Version

To enable a single theme with confirmation

  1. Type the following command from your Drupal server
    ~/drush/drush pm-enable themename
    eg: ~/drush/drush pm-enable vert

  2. In sites/all/themes folder type
    drush pm-enable themename
    eg: drush pm-enable business_blog

To enable a single theme without confirmation

  1. Type the following command from your Drupal server
    ~/drush/drush pm-enable themename --yes
    eg: ~/drush/drush pm-enable vert --yes

  2. In sites/all/themes folder type
    
    drush pm-enable themename --yes
    eg: drush pm-enable black_blog --yes

List all themes with the associated info

  1. Type the following command from your Drupal server
    ~/drush/drush pm-list --type=theme | tr -s ' '
  2. In sites/all/themes folder type
    drush pm-list --type=theme | tr -s ' '

Cut each column

  1. Type the following command from your Drupal server
    ~/drush/drush pm-list --type=theme | tr -s ' '| cut -f1 -d' '
    ~/drush/drush pm-list --type=theme | tr -s ' '| cut -f2 -d' '~/drush/drush pm-list --type=theme | tr -s ' '| cut -f3 -d' '
    
  2. In sites/all/themes folder type
    drush pm-list --type=theme | tr -s ' '| cut -f1 -d' '
    drush pm-list --type=theme | tr -s ' '| cut -f2 -d' '
    drush pm-list --type=theme | tr -s ' '| cut -f3 -d' '

Display all theme names

  1. Type the following command from your Drupal server
    ~/drush/drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*//
    
  2. In sites/all/themes folder type
    drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*//

Write all the themes to a themelist file

  1. Type the following command from your Drupal server
    ~/drush/drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// > themelist
  2. In sites/all/themes folder type
    drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// > themelist
  3. Make sure that the file contains only theme name and not any other content. You can edit the file using following commands
    less themelist
    nano themelist
    wc -l themelist

Display all the themes from themelist file

  1. for i in `cat themelist`; do  echo $i; done
    

Enable all the themes (with confirmation required)

  1. Type the following command from your Drupal server
    for i in `cat themelist`; do  ~/drush/drush en $i; done
  2. In sites/all/themes folder type
    for i in `cat themelist`; do  drush en $i; done

Enable all the themes (without confirmation)

  1. Type the following command from your Drupal server
    for i in `cat themelist`; do  ~/drush/drush en $i --yes; done
  2. In sites/all/themes folder type
    for i in `cat themelist`; do  /drush en $i --yes; done
  3. Hope you have find this article useful. Feel free to give your feedback via the comment form below .