Just wondering if Drush is capable of deleting nodes of a given content type.

Something like: $ drush delete-node --type=MyContentType

If not possible, can I create a method like that?


15 Answers 15


You could create a function like follows:

function MYMODULE_delete_all_the_things() {
  $query = new EntityFieldQuery;

  $result = $query->entityCondition('entity_type', 'node')
    ->propertyCondition('type', 'YOUR-CONTENT-TYPE')

  if (isset($result['node']) && count($result['node'])) {

    $node_ids = array_keys($result['node']);


Note - You could also use a simple SELECT query, but seeing as you're working with entities it seems more sensible/common-practice to use EntityFieldQuery.

This should also be quite easy to change or add arguments to. You can also put it in a Drush command quite easily - there's an example for how to do this in the Drush repository (check the Commands section near the bottom).

  • I see, it sound like the repository link shows how to properly add a drush method.
    – chefnelone
    Commented Jun 14, 2012 at 11:57
  • Yup! The readme has some different ways you can implement them as well!
    – Chapabu
    Commented Jun 14, 2012 at 12:18

Drush 9

drush entity:delete node --bundle=my_content_type

  • 3
    Best answer nowadays!
    – Jonathan
    Commented Apr 18, 2019 at 12:03
  • Best answer ! i just tried it . Commented Oct 5, 2022 at 8:30

Install the devel module, and use drush to delete all the nodes,

$  drush genc --kill 0 0 

You can also give a type option,

$  drush genc --kill --types=article 0 0
  • Clever, I like it.
    – m4olivei
    Commented Dec 29, 2014 at 19:19
  • 3
    This works with D8. The devel_generate module is included with devel, but needs to be enabled with drush en devel_generate genc is normally used to create nodes, so the 0 0 at the end is telling it not to create anything new, and the --kill to remove what's already there. Commented Dec 14, 2016 at 11:24

I guess you can by using the below command

drush node_delete <nid>

EDIT: Found a module that does something/related to the question




drush delete-all

Example: drush delete-all article


Something like this would work (untested):

$query = new EntityFieldQuery();

$entities = $query->entityCondition('entity_type', 'node', '=')
  ->entityCondition('bundle', 'Announcements')

$nids = array_keys($entities['node']);


This will find all of the nodes with the content type Annoucements using EntityFieldQuery(). It then gets all the $nids from the result, and deleted them using node_delete_multiple().

You can take this code, put it in a separate PHP file, and then execute it with drush scr.

Using the API will ensure that all of the proper hooks fire. Among other things, they will also delete the node revisions and field data (and their revisions) so you don't have orphaned data in the database.


There are some good ideas on this thread. If you dont want to do any programming really and want to use Drush you can look at the Delete All contributed module:

drush delete-all
Example: drush delete-all article

Drush on Drupal 7 version

Delete all nodes, nodes of a specific content type or users.

 drush delete-all article             Delect all article nodes.
 drush delete-all all                 Delete nodes of all types.
 drush delete-all --reset             Delete nodes of all types, and reset node, revision and comment counters.
 drush delete-all users               Delete users.

 --reset                              Reset counter for node, revision and comment tables.
 --roles                              pick roles

Aliases: da

VBO has Drush integration. Create a VBO view of nodes, execute it via Drush (using drush vbo-execute), pass the node type as an argument.

  • I think that this is what I need.Just 2 questions: Which is the drush method to execute a view? and Will this method be faster than executing the view in the browser?
    – chefnelone
    Commented Jun 14, 2012 at 11:47
  • Edited the answer to specify the exact drush command. And yes, it will be faster because this way the view isn't rendered. Commented Jun 15, 2012 at 12:10

You can also create a drush script (let's say it's called "bulk_delete.php" and is placed under the Drupal root folder):

#!/usr/bin/env drush

$res = db_delete('node')
  ->condition('type', 'mycontenttype', '=')

echo "deleted:" . $res;

This is absolutely the fastest way to do it: a direct query to the db, using the Drupal's function db_delete


:~# cd /var/www/www.mysite.com
:~# drush --uri=www.mysite.com scr bulk_delete.php 

Doc: https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_delete/7

Warning: this process does not delete the data of their fields. Anyway the same process can be applied to these fields (looking at the "bundle" column of each field). For example:

#!/usr/bin/env drush

$field_tables = array(

foreach ($field_tables as $field_table) {
  $res = db_delete($field_table)
    ->condition('bundle', 'mycontenttype', '=')

  echo "deleted:" . $res . "\n\n";

Where "mycontenttype" is the one used in the first query.

  • Why the condition 'nid' > 5000?
    – Elin Y.
    Commented Oct 8, 2013 at 17:12
  • it's an example, like the type. Commented Oct 8, 2013 at 17:23
  • But the original poster doesn't mention about such a condition, that's why I think the example is irrelevant, thus misleading.
    – Elin Y.
    Commented Oct 8, 2013 at 17:31

Drupal 7

Try the following one-liner, it removes all MyContentType nodes from Drupal:

drush eval '$res = (new EntityFieldQuery)->entityCondition("entity_type", "node")->entityCondition('bundle', 'MyContentType')->execute(); entity_delete_multiple("node", array_keys(reset($res)));'

Or you can remove all the entities based on the entity type name (e.g. node):

drush eval '$res = (new EntityFieldQuery)->entityCondition("entity_type", "node")->execute(); entity_delete_multiple("node", array_keys(reset($res)));'

Note: node is your entity type name, you can change it if required.

If you'll get memory or time out errors, you may add the following sets just before the $res:

ini_set('memory_limit', -1); ini_set('max_execution_time', 0);

To delete all nodes of a particular content type, you may try to run the following command via drush:

drush eval '$res = (new EntityFieldQuery)->entityCondition("entity_type", "node")->entityCondition('bundle', 'MyContentType')->execute(); entity_delete_multiple("node", array_keys(reset($res)));'

Where MyContentType is your machine Content Type name (e.g. Page).


For individual nodes:

$ drush php-eval 'node_delete($node->nid);'

drush php-eval
Evaluate arbitrary php code after bootstrapping Drupal

  • Please add some more details to explain your code, without that this may be considered as a low quality answer (and hence it might get deleted via moderation). Commented Nov 25, 2016 at 8:32

Updating the answer provided by @kenorb.

In Drupal 8

drush eval '$nids = \Drupal::entityQuery('node')->execute(); $storage = Drupal::entityTypeManager()->getStorage('node'); $e = $storage->loadMultiple($nids); $storage->delete($e);'
  • drush ev '$type='\''node'\''; entity_delete_multiple($type, \Drupal::entityQuery($type)->execute());' Commented May 3, 2018 at 13:04
  • To update an existing answer, please drop a comment to suggest an edit.
    – leymannx
    Commented Oct 18, 2018 at 8:09

To help those that find this thread - use the following command to delete all the nodes within a content type - drush uses bundles now instead of types:

drush genc --kill --bundles=about 0 0

You can also do this with the devel module as answered at Can I delete nodes of a given content type with Drush?

Install the devel module, and use drush to delete all the nodes,

$ drush genc --kill 0 0

You can also give a type option,

$ drush genc --kill --types=article 0 0


You can use

drush node_delete NID to delete specific node, but if you want to delete all nodes by content type I guess you can create a drush plugin using batch api.

  • I can't found the drush node_delete NID command. Commented Jun 22, 2016 at 14:44
  • That command doesn't exists
    – DarkteK
    Commented Aug 10, 2021 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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