How can I get the existing content type list with drush? this will allow me to quickly produce a list.

I've tried with:

$ drush @d6 @sites genc --types

But I need devel_generates module enabled for this.

Command genc needs the following module(s) enabled to run: devel_generate.

up vote 7 down vote accepted

You can create a drush command named content-type-list. Create a module named drush_content_types, inside the drush_content_types.drush.inc file put this code:

<?php
/**
 * @file
 * Drush commands related to Content Types.
 */

/**
* Implements hook_drush_command().
*/
function drush_content_types_drush_command() {
  $items['content-type-list'] = array(
    'description' => dt("Show a list of available content types."),
    'aliases' => array('ctl'),
  );
  return $items;
}

/**
 * Callback for the content-type-list command.
 */
function drush_drush_content_types_content_type_list() {
  $content_types = array_keys(node_type_get_types());
  sort($content_types);

  drush_print(dt("Machine name"));
  drush_print(implode("\r\n", $content_types));
}

Install the module, run drush cc drush to clear the drush cache and use the command like this:

drush ctl

or

drush content-type-list

If you want add another alias to the command add elements to the aliases array like this:

'aliases' => array('ctl', 'all-content-types', 'act'),

And you can use this commands:

drush act
drush all-content-types
drush ctl
drush content-type-list

Always the output will be:

Machine name:
content 1
content 2
content...
content n

You can try

drush sqlq "SELECT name FROM node_type;" if you want a list of names or

drush sqlq "SELECT type FROM node_type;" if you want the machine names used.

This works in D6 and D7.

The first line of the command's output will be name or type, respectively. Pipe |tail -n +2 if you want to drop that first line.

  • trying but get errors: $ drush @d6mg sqlq "SELECT type FROM node_type;" ERROR 1146 (42S02) at line 1: Table 'drupal6_mg.node_type' doesn't exist $ drush @d6mg sqlq "SELECT name FROM node_type;" ERROR 1146 (42S02) at line 1: Table 'drupal6_mg.node_type' doesn't exist – webmaster pf Jan 6 '14 at 11:16
  • 1
    @webmaster_pf, I just checked this again, works fine. Do you have a table_prefix on this site? What does drush sqlq "SHOW TABLES;"|grep type give you? – guaka Jan 9 '15 at 22:01
  • yes i have prefix but your command give me a list of tables .this is the right command :drush sqlq "SHOW TABLES;"|grep content_type – webmaster pf Jan 23 '15 at 9:27

Try the following commands.

Drupal 7 & 8

drush ev "print_r(array_keys(node_type_get_types()));"

Drupal 5 & 6

drush ev "print_r(array_keys(node_get_types()));"

If you know how to do it in Drupal, you just need to use drush eval:

drush eval '$types = node_type_get_types(); foreach($types as $type => $object) { print $type . "\n"; }'

See this list of drush commands for other useful examples using eval.

Edit: I see that the question was for Drupal 6, and node_type_get_types() is for Drupal 7 only. You may find and alternative for node_type_get_types() in Drupal 6, and eval will be the way to go.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.