If you manage more than one WordPress site, or even one site you care about, WP-CLI is the tool that will change how you work. It’s the official command line interface for WordPress, and it lets you do almost anything you’d do in the dashboard, plus many things the dashboard can’t do, from a terminal.
Updating twenty plugins across five sites, searching and replacing URLs in a database safely, resetting a forgotten admin password, finding which plugin is causing a fatal error: all of these take seconds with WP-CLI. I use it every day, and many of the procedures in my other articles depend on it.
Here are the commands I use most, grouped by what they’re for.
Getting started
WP-CLI is usually installed as a single file. Many hosts already provide it. To check:
Run commands from inside the WordPress directory, or use –path to point to it. On servers, run WP-CLI as the same user that owns the site files, not as root. Running as root creates files owned by root, which can cause permission problems later. WP-CLI warns you if you try.
Every command has built-in help:
Core updates and information
core verify-checksums compares core files with official versions and reports anything modified. It’s one of the first commands I run when investigating a possible hack.
Plugins and themes
A few tricks I use often:
Find a plugin causing a problem. If a site has a fatal error and you can’t reach the dashboard, deactivate all plugins, then reactivate them one at a time:
Skip plugins and themes when the site is broken. If a plugin is causing fatal errors, even WP-CLI might fail to load. These flags skip loading them:
Update with a dry run first:
Database essentials
Search and replace
This is probably the most valuable WP-CLI command. When you change a domain or move from HTTP to HTTPS, URLs are stored throughout the database, including inside serialised data. A plain text find and replace on an SQL file corrupts serialised data, because string lengths change. WP-CLI handles serialisation correctly:
Always run a dry run first and check the number of replacements. You can also export the result to a new file instead of changing the database:
Searching the database
When hunting for injected scripts or spam:
Users
Resetting an admin password when someone is locked out is a common request. user update does it instantly. Note that passwords typed on the command line may be saved in your shell history, so clear it or use the reset option that emails a link instead:
For removing users, always use –reassign so their content is transferred instead of deleted.
Options and configuration
config shuffle-salts regenerates the security keys in wp-config.php, logging out every user. It’s an essential step after a security incident.
Posts and content
Creating content in bulk, deleting revisions and inspecting post meta are all much faster here than through the dashboard.
Cron and scheduled tasks
I use cron event run –due-now with a system cron job to replace WP-Cron on servers. cron event list is also useful for spotting malicious scheduled tasks or plugins scheduling far too many events.
Cache and transients
If permalinks suddenly return 404 errors, wp rewrite flush often fixes it. cache flush clears the object cache, which is useful after direct database changes.
Media
After changing a theme’s image sizes, regenerate thumbnails so existing images get the new sizes. –only-missing is faster on large libraries.
Maintenance mode
Handy during deployments or larger updates.
Debugging
eval runs a line of PHP in the context of WordPress. shell opens an interactive PHP session with WordPress loaded, which is brilliant for testing functions or inspecting data. The doctor command, a separate package, runs a series of health checks for common problems.
Working with remote sites
WP-CLI can run commands on remote servers over SSH using aliases defined in a config file. In ~/.wp-cli/config.yml:
Then:
You can even define a group alias to run the same command across several sites at once. For anyone managing multiple sites, this is a huge time saver.
Scripting and automation
The real power of WP-CLI comes from combining it with shell scripts. For example, a simple update routine with a backup first:
Or a loop across several sites:
Output formats like –format=json, csv, ids and count make WP-CLI easy to use in scripts and other tools.
Scaffolding
Scaffolding generates boilerplate for plugins, child themes, post types and more. It’s a quick way to start new code with a sensible structure.
Safety habits
WP-CLI is powerful, which means it can do damage quickly. A few habits help:
- Back up before destructive commands.
- Use –dry-run wherever it’s available.
- Double check the –path or alias, so you don’t run a command on production when you meant staging.
- Read the output, especially counts of changed items.
Commands I use during incident response
WP-CLI is at its most valuable when something has gone wrong. When I investigate a possibly hacked site, a handful of commands give me a quick picture before I start digging into files and logs. Checksum verification of core and plugins shows which files were tampered with. Listing administrators, sorted by registration date, reveals accounts created recently. Listing cron events shows scheduled tasks that might be recreating malware. Searching the database for script tags and iframes finds injected content. And regenerating the salts logs out every session, including the attacker’s.
All of these are read-only apart from the last one, which is exactly what you want in the early stages of an investigation. You can gather evidence without changing the state of the site, then decide what to clean once you understand the scope.
Making WP-CLI part of your routine
The best way to learn WP-CLI is to replace one dashboard habit at a time. Next time you need to update plugins, do it from the command line. Next time you need to check which version of WordPress a site runs, use wp core version instead of logging in. When you migrate a site, use search-replace with a dry run instead of a plugin.
Within a few weeks, the commands become muscle memory. You’ll start noticing tasks that would take ten minutes of clicking and realise they can be a single line, or a short script you run across every site you manage.
It’s also worth keeping a personal cheat sheet of the commands you use most, with the exact flags you prefer. Mine lives in a text file alongside my server notes. When I need a command I use only occasionally, such as regenerating thumbnails only for missing sizes or exporting search-replace results to a file, I don’t have to look it up.
Using WP-CLI safely on production
Command line access to production deserves respect. A few extra habits protect you from expensive mistakes. Always confirm which server and which site you’re connected to before running anything destructive; a quick wp option get siteurl takes a second and prevents disasters. Use a separate SSH user for each environment so your terminal prompt makes it obvious where you are. Take a database export before any command that modifies data in bulk. And when you write scripts that loop over several sites, test them on staging first and add a confirmation step before anything irreversible runs.
Treat WP-CLI as a power tool. Used carefully, it makes you faster and more precise than any dashboard ever could.
When you write your own WP-CLI scripts, add plenty of echo lines so the output shows what’s happening at each step. A script that runs silently is hard to trust, and harder to debug when it fails halfway through a batch of sites. Clear output, plus a log file for longer jobs, makes automated maintenance something you can rely on.
Frequently asked questions
Do I need SSH access to use WP-CLI?
Yes, WP-CLI runs on the server, so you need command line access. Many hosts offer SSH on their plans. You can also run it locally against local development sites.
Can WP-CLI break my site?
Like the dashboard, it does what you tell it. Commands like search-replace, db import and delete can cause damage if used carelessly. Back up first and use dry runs.
Can I manage WooCommerce with WP-CLI?
Yes. WooCommerce registers its own commands for products, orders, customers and more, built on its REST API. Run wp help wc to explore them.
Is WP-CLI worth learning for a single site?
Absolutely. Even for one site, tasks like safe search and replace, troubleshooting fatal errors and quick backups are much easier from the command line.
Final thoughts
WP-CLI turns repetitive, error-prone dashboard tasks into fast, repeatable commands. Learn the essentials for core, plugins, the database, users and cron, add aliases for your sites and start scripting routine work. Within a few weeks, you’ll wonder how you ever managed WordPress without it.




