Managing a Drupal site often requires quick access to user data. Whether you are auditing accounts, checking roles, or verifying email addresses, the command line is your best friend. While the standard drush user-information (or drush uinf) command is excellent for inspecting a single account, it doesn't natively provide a full directory of every user on your site.

In this guide, you will learn how to list all users using Drush across different versions of Drupal, from the modern users:list command in Drush 9+ to powerful SQL-based workarounds for legacy systems. By the end of this article, you will be able to efficiently pull user reports directly from your terminal.

Using the Modern Drush users:list Command

If you are working with a modern Drupal installation (Drupal 8, 9, 10, or 11) and using Drush 9 or higher, you have access to a dedicated command specifically designed for this purpose. This is the most robust and recommended method for modern development workflows.

To see a full table of your users, run:

drush users:list

This command generates a clean, formatted table including the User ID (UID), Username, Email, and Roles. This is significantly more efficient than trying to fetch users one by one.

Advanced Filtering and Formatting

You can extend this command with standard Drush flags to tailor the output to your needs. For example, if you need to export this list to a spreadsheet, you can change the output format:

drush users:list --format=csv > users-export.csv

If you only want to see users with a specific role, or if you want to limit the fields shown, use the --fields and --filter flags provided by the Drush annotation system. You can always run drush users:list --help to see the full list of available options for your specific Drush version.

The SQL Process Substitution Workaround

For older versions of Drupal (like Drupal 7) or environments where specific Drush extensions aren't installed, you might find that drush uinf is your only built-in tool. Since drush uinf accepts a list of identifiers, you can combine it with a sub-query to list everyone.

This technique uses "process substitution" to feed the results of a database query directly into the Drush command.

For Drupal 7

In Drupal 7, user data is stored in the users table. You can fetch all UIDs and pass them to the information command like this:

drush uinf $(drush sqlq "SELECT GROUP_CONCAT(uid) FROM users")

For Drupal 8 and Beyond

In Drupal 8 and later, the database schema changed to support multilingual content. User data is now primarily found in the users_field_data table. If you aren't using drush users:list, you can use this SQL approach:

drush uinf $(drush sqlq "SELECT GROUP_CONCAT(uid) FROM users_field_data")

Why Use UID Instead of Username?

You might see some developers use GROUP_CONCAT(name). However, it is highly recommended to use the uid (the integer ID). Usernames can contain spaces, special characters, or symbols that might break the command line argument parsing. Using the integer ID ensures the command remains stable regardless of how your users have named their accounts.

Listing Users in Legacy Drupal (D6 & D7)

If you are maintaining a legacy site and want a more permanent solution than a one-liner SQL query, there are community-contributed Drush extensions. One such example is the drush_user_list project.

Once installed in your .drush folder or site-specific modules folder, it provides a simple command:

drush user-list

While these sandbox projects were helpful in the past, most developers today prefer the SQL injection method for D7 or the native users:list for modern Drupal, as they don't require maintaining additional code dependencies.

Understanding the Output

When you use the drush uinf method combined with an SQL query, your output will look like a sequence of individual user profiles. This is particularly useful when you need to see the status and roles of every user in a detailed view:

 User ID       :  1
 User name     :  admin
 User mail     :  [email protected]
 User roles    :  authenticated, administrator
 User status   :  1

 User ID       :  2
 User name     :  editor_john
 User mail     :  [email protected]
 User roles    :  authenticated, editor
 User status   :  1

Frequently Asked Questions

Can I list users by a specific role using these commands?

Yes. If you are using drush users:list, you can use the --role filter (e.g., drush usl --role=administrator). If you are using the SQL workaround, you would need to modify your SQL query to join the users_roles table and filter by the rid (Role ID) before passing the IDs to drush uinf.

Will listing all users affect site performance?

On sites with a few hundred or even a few thousand users, these commands run almost instantly. However, if you have a site with tens of thousands of users (like a large community portal), running drush uinf on every single UID can be slow and memory-intensive because Drush has to bootstrap and load every user entity. In those cases, it is better to use drush sqlq to export just the specific columns you need directly from the database.

Why does drush uinf say 'User not found' for UID 0?

In Drupal, UID 0 represents the "Anonymous" user. This is a special record in the database. Depending on your version of Drupal and Drush, attempting to load information for UID 0 may return an empty result or an error because it isn't a "real" authenticated user account.

Wrapping Up

Mastering the command line is a hallmark of an efficient Drupal developer. While drush uinf is the go-to for checking a single user, knowing how to leverage drush users:list or the sqlq process substitution trick gives you total control over your user database.

  • For Drush 9+: Use drush users:list for the cleanest experience.
  • For Legacy/Custom Needs: Use drush uinf $(drush sqlq "SELECT GROUP_CONCAT(uid) FROM users_field_data").
  • For Exporting: Always use the --format=csv or --format=json flags to make your data portable.

By using these commands, you can perform user audits and site maintenance in seconds rather than clicking through pages of the administrative UI.