Repeating the same WordPress job in wp-admin gets slow once it spans dozens of plugins, users or sites. WP-CLI runs that work from the terminal, but one wrong flag or folder can rewrite a live database in seconds.
This WP-CLI commands cheat sheet groups the commands by the job in front of you, from installing WordPress to clearing cache and running cron. Our advice is to learn the read-only commands first and to export the database before any command that writes.
WP-CLI Commands at a Glance
These are the commands most WordPress jobs start with. The last column matters most, because a command that changes the site deserves a backup first.
| Task | Command | Changes the site? |
|---|---|---|
| Check WP-CLI and PHP | wp --info | No |
| Confirm which site you're on | wp option get home | No |
| Download WordPress | wp core download | Adds core files |
| Create wp-config.php | wp config create | Adds a file |
| List pending plugin updates | wp plugin list --update=available | No |
| Update every plugin | wp plugin update --all | Yes |
| Back up the database | wp db export backup.sql | Writes a file only |
| Restore a database | wp db import backup.sql | Yes, overwrites tables |
| Preview a URL change | wp search-replace OLD NEW --dry-run | No |
| Reset a password | wp user reset-password | Yes |
| Empty the object cache | wp cache flush | Yes, temporarily |
| Run due cron events | wp cron event run --due-now | Yes |
| Rebuild missing thumbnails | wp media regenerate --only-missing | Adds image files |
wp help followed by a command name prints every option for that command, and the official WP-CLI command reference covers the same ground online. Some options in that reference only exist in the nightly build, such as --with-dependencies for wp plugin install, so everything on this page sticks to the stable release.
Install WP-CLI
WP-CLI needs PHP 7.2.24 or later and nothing beyond what WordPress itself needs. Many managed hosts already include it, so wp --info is worth running before you install anything.
On your own server, the official installation guide uses the Phar file, a single PHP archive:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --infowp --info reports the PHP binary, the php.ini file and the WP-CLI version, so a PHP mismatch shows up before it breaks a command. wp cli version prints the installed release and wp cli update replaces a Phar install with the latest one.
Two other setups come up often:
- No sudo on shared hosting: the Phar can stay in your home folder, with
alias wp='php ~/bin/wp-cli.phar'added to~/.bashrc. - macOS:
brew install wp-cliinstalls it through Homebrew, which the handbook lists as a supported method.
Install WordPress and Create wp-config.php
A fresh install from the terminal takes 4 commands. They run from the empty folder that will become the site root, or from anywhere with --path pointing at it.
wp core download --locale=en_US
wp config create --dbname=example_db --dbuser=example_user --prompt=dbpass
wp db create
wp core install --url=https://example.com --title="Example Site" --admin_user=example_admin --admin_email=admin@example.com --prompt=admin_password--prompt=dbpass and --prompt=admin_password ask for each password instead of taking it on the command line. That keeps both out of your shell history, which matters on any server other people can log in to.
wp config createchecks that the user can connect to the database server before it writes the file. The database itself doesn't have to exist yet, and--skip-checkturns the check off.wp db createneeds a database user that is allowed to create databases. On most shared hosts the database is created in the control panel instead, so this step gets skipped.wp config set WP_DEBUG true --rawadds or changes any constant later.--rawwrites a PHP boolean instead of the text'true'.
This Does Not Seem to Be a WordPress Installation
WP-CLI looks for wp-includes/version.php in the current folder, or in the folder --path names. When that file isn't there, every command except wp core download stops with this error:
Error: This does not seem to be a WordPress installation.
The used path is: /home/example/
Pass --path=`path/to/wordpress` or run `wp core download`.The usual causes are these:
wp config createbeforewp core download: the config command checks for core files first, so it fails in an empty folder. Downloading core first fixes it.- The wrong folder: the shell is in the home directory instead of
public_htmlor the site root. Acdinto the folder that holdswp-config.php, or--path, fixes it. - WordPress in a subfolder: some setups keep core in a folder such as
/wp.--pathor apath:line inwp-cli.ymlpoints WP-CLI there. - A stale
wp-cli.yml: WP-CLI reads that file from the current folder and every folder above it, so an oldpath:value can send it somewhere else.
cd /var/www/example.com/public_html
ls wp-includes/version.php
wp core version
wp core version --path=/var/www/example.com/public_html2 related errors point at the next step. "It seems, the WordPress core files do not have the proper file permissions" means the files exist but your user can't read them, which our WordPress file permissions guide covers. "'wp-config.php' not found" means core is in place and wp config create is the missing step.
Update WordPress Core, Plugins and Themes
Updates are a common WP-CLI job, and a careless --all can break several plugins at once. This is the order we'd follow on a live site: check what's pending, back up, then update core before plugins and themes.
wp core check-update
wp plugin list --update=available
wp theme list --update=available
wp db export before-updates.sql
wp core update
wp core update-db
wp plugin update --all --dry-run
wp plugin update --all --exclude=woocommerce
wp theme update --all
wp language core updatewp core update --minorlimits a core update to maintenance and security releases on the current branch.wp plugin updatetakes--minorand--patchfor the same restraint, plus--excludefor plugins that need a manual test first.--dry-runlists the plugins that would update without changing anything.- WP-CLI switches maintenance mode on during
wp plugin update --alland off when the updates finish. wp core update-dbruns the database upgrade a new core version can need, the step wp-admin normally prompts for.
For a site you look after every month, our WordPress maintenance guide covers what to check around these commands.
Check Core and Plugin Files for Changes
After an update or a suspected hack, wp core verify-checksums compares every core file with the checksums WordPress.org publishes. wp plugin verify-checksums --all does the same for plugins from the WordPress.org directory.
wp core verify-checksums
wp plugin verify-checksums --allA clean result only covers those files. Malicious code in uploads, a premium plugin, the database or a cron event won't show up in either check.
Manage Plugins and Themes
Plugin and theme commands accept a WordPress.org slug, a local ZIP file or a ZIP URL. The slug is the folder name, such as akismet, rather than the display name.
wp plugin list --status=active
wp plugin install hello-dolly --activate
wp plugin install ../my-plugin.zip --activate
wp plugin activate akismet
wp plugin deactivate akismet
wp plugin status akismet
wp plugin delete hello-dolly
wp theme list
wp theme install twentytwentyfive --activate
wp theme activate twentytwentyfive
wp theme delete twentytwentythreewp plugin deleteremoves the files without deactivating the plugin or running its uninstall routine.wp plugin deactivate --uninstalldeactivates it and runs that cleanup.wp theme deleterefuses the active theme unless--forceis added.wp plugin installwith--versionfetches a specific release from WordPress.org, which helps when the latest one breaks something.
When a site breaks and a plugin is the likely cause, wp plugin deactivate --all rules plugins in or out in one step. It is wise to save the active list first, because wp plugin activate --all would also switch on plugins that were off before:
wp plugin list --status=active --field=name > active-plugins.txt
wp plugin deactivate --all
wp plugin activate $(cat active-plugins.txt)Manage Users
User commands beat wp-admin when you need to audit administrators, lock someone out or fix an account you can't log in to.
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
wp user create jane jane@example.com --role=editor --send-email
wp user reset-password jane --skip-email --show-password
wp user set-role jane author
wp user session destroy jane --all
wp user delete 12 --reassign=1wp user createprints a generated password when--user_passis left out, and--send-emailemails the new user.wp user reset-passwordemails the user by default.--skip-email --show-passwordprints the new password in the terminal instead.wp user session destroy --alllogs a user out on every device, a sensible first step after a suspected account takeover.wp user deletewithout--reassigndeletes that user's posts along with the account. On multisite it only removes the user from the current site unless--networkis added.
Export and Import the Database
wp db export and wp db import read the credentials from wp-config.php and call the MySQL tools for you. That makes them the quickest backup and restore on any server with shell access.
wp db export backup.sql
wp db export --tables=wp_posts,wp_postmeta posts.sql
wp db export --exclude_tables=wp_users,wp_usermeta no-accounts.sql
wp db export - | gzip > backup.sql.gz
wp db import backup.sql
gunzip < backup.sql.gz | wp db import -wp db importoverwrites any table with the same name. It doesn't create the database, sowp db createcomes first on an empty server.- Table names follow the site's prefix.
wp db prefixprints it, since plenty of sites don't usewp_. - The
-sends the export to standard output and lets the import read from it, which keeps the gzip step in one line. - An export holds every password hash and email address on the site. It belongs outside the web root, never in a folder a browser can reach.
Moving a whole site also means moving the files, which our WordPress migration tutorial walks through. A manual export protects only the moment you ran it, so scheduled copies still come from the host or one of the WordPress backup plugins we compared.
Check and Maintain the Database
wp db check
wp db size --tables --human-readable
wp db optimize
wp db repair
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_status = 'trash'"
wp db reset --yeswp db size --tables is a good first look when the admin feels slow, because one oversized log or options table stands out quickly. wp db reset --yes drops every table without asking, so it belongs on local and staging copies only.
Teams that share a server often block it outright with a disabled_commands list in wp-cli.yml. That is a cheap guard against a reset typed into the wrong terminal.
Search and Replace URLs
wp search-replace swaps one string for another across the database and handles serialized PHP data, which a plain SQL UPDATE corrupts. It is the standard step after a domain change or a move from HTTP to HTTPS.
wp search-replace 'https://staging.example.com' 'https://example.com' --dry-run
wp search-replace 'https://staging.example.com' 'https://example.com' --skip-columns=guid
wp search-replace 'http://example.com' 'https://example.com' --all-tables-with-prefix --precise
wp search-replace 'https://old.example' 'https://new.example' --export=migrated.sqlOur advice is to read the dry-run counts before the real run and to leave the guid column alone on a live site. The full workflow, with multisite and regex cases, lives in our WP-CLI search-replace guide.
Clear Cache, Transients and Rewrite Rules
These commands clear stored data that WordPress and its plugins rebuild on demand. The cost is a few slower page loads while that data fills back in.
wp cache type
wp cache flush
wp cache flush-group my_group
wp transient list
wp transient delete --expired
wp transient delete --all
wp rewrite flush
wp rewrite flush --hardwp cache typenames the object cache in use. "Default" means no persistent cache, so a flush only clears memory for that one command.wp cache flushempties the object cache, such as Redis or Memcached. It doesn't purge a page cache plugin or a CDN, which have their own commands or dashboards.wp cache flush-groupneeds WP-CLI 2.8 or later and an object cache that supports group flushing.wp transient delete --expiredis routine housekeeping.--allremoves every transient, so plugins rebuild them on the next requests.wp rewrite flushfixes 404 errors after a permalink or custom post type change.--hardalso rewrites the Apache rules file (.htaccess) and works on single sites only.
Page caching is a separate layer, and our WordPress caching plugins comparison covers how each one clears it.
Run and Debug WP-Cron
WP-Cron runs scheduled jobs when someone loads a page, so on a quiet site backups, emails and scheduled posts can fire late. These commands show what is queued and run it on demand.
wp cron event list
wp cron event list --fields=hook,next_run_relative,recurrence
wp cron event run --due-now
wp cron event run wp_version_check
wp cron event delete my_old_hook
wp cron schedule list
wp cron testFor time-sensitive jobs, it is wise to move WP-Cron to a real server cron. The switch takes 2 parts: a constant that stops the page-load trigger and a crontab line that runs due events every 5 minutes.
wp config set DISABLE_WP_CRON true --raw*/5 * * * * /usr/local/bin/wp --path=/var/www/example.com cron event run --due-now --quietCron runs with a short PATH, so the full path to wp matters. After the change, wp cron test reports an error because DISABLE_WP_CRON is set, which is expected.
Manage Media
Media commands rebuild thumbnails after a theme changes its image sizes and import files without the upload screen.
wp media image-size
wp media regenerate --only-missing --yes
wp media regenerate 123 124 --image_size=large
wp media import ~/Downloads/photo.jpg --post_id=123 --title="Team photo" --featured_imagewp media image-sizelists every registered size, so you can see what a regenerate will build.--only-missingfills the gaps after a new size is added, without redoing every image.- A regenerate deletes old thumbnails by default.
--skip-deletekeeps them when other sites or emails link to those files. --yesskips the confirmation prompt for a full run.
Posts, Options and wp-config.php
These are the everyday reads and edits. wp option get home belongs before any write, because it confirms which site the shell is pointed at.
wp post list --post_type=page --post_status=draft --fields=ID,post_title
wp post update 123 --post_status=publish
wp post delete 123
wp post delete 123 --force
wp option get home
wp option get siteurl
wp option update blogname "Example Site"
wp option list --autoload=on --format=total_bytes
wp config get DB_NAME
wp config set WP_DEBUG_LOG true --raw
wp config shuffle-salts
wp maintenance-mode activate
wp maintenance-mode deactivatewp post deletemoves a post to the trash.--forceskips the trash and deletes it for good.wp option list --autoload=on --format=total_bytesprints the total size of autoloaded options, which WordPress loads on every request.wp config shuffle-saltsreplaces the keys and salts in wp-config.php, which logs every user out.wp exportwrites a WXR file andwp importreads one, but import runs through the WordPress Importer plugin, sowp plugin install wordpress-importer --activatecomes first.
Multisite and Remote Sites
On multisite, --url picks the subsite a command runs against, and without it WP-CLI works on the main site. Our WordPress multisite setup guide covers the network side.
wp site list --field=url
wp plugin list --url=https://example.com/blog/
wp site list --field=url | xargs -I % wp plugin list --url=%
wp core update-db --networkFor other servers, aliases in wp-cli.yml save typing the SSH details each time. WP-CLI has to be installed on the remote server too.
@staging:
ssh: deploy@staging.example.com
path: /var/www/staging
@production:
ssh: deploy@example.com
path: /var/www/example.comwp @staging plugin list
wp @production option get homeGlobal Flags
Global flags work with every command. Two flags people often treat as global, --dry-run and --format, belong to individual commands, so wp help is the place to check whether a command has them.
| Flag | What it does |
|---|---|
--path=<path> | Points WP-CLI at a WordPress folder |
--url=<url> | Picks the site, and the subsite on multisite |
--ssh=<host> | Runs the command on a remote server over SSH |
--user=<id|login|email> | Runs as a WordPress user, for capability checks |
--skip-plugins[=<plugins>] | Skips loading all plugins or the ones listed; mu-plugins still load |
--skip-themes[=<themes>] | Skips loading all themes or the ones listed |
--skip-packages | Skips installed WP-CLI packages |
--require=<path> | Loads a PHP file before the command |
--exec=<php-code> | Runs PHP code before the command |
--context=<context> | Loads WordPress as cli or admin; the default auto uses admin for plugin and theme commands |
--debug[=<group>] | Shows PHP errors and extra WP-CLI output |
--prompt[=<assoc>] | Asks for argument values instead of reading them from the command line |
--quiet | Hides informational messages |
--[no-]color | Turns colored output on or off |
When WP-CLI Commands Fail
Most failures come from 4 places: the folder, the system user, the database or PHP itself. The error text usually says which one.
- "This does not seem to be a WordPress installation": the folder has no core files. The install section above covers each cause.
- "YIKES! It looks like you're running this as root": WP-CLI stops because plugin code would then run with full control of the server.
sudo -u USER -i -- wp plugin listruns it as the site's own user instead. - "Error establishing a database connection":
wp config get DB_HOSTandwp db checkshow whether the credentials or the database server is the problem. - "Allowed memory size exhausted": with a Phar install,
php -d memory_limit=512M "$(command -v wp)" media regenerate --yesraises the limit for one run.WP_CLI_PHP_ARGSonly works for installs that don't use the Phar. - A plugin fatal error stops every command:
wp plugin deactivate broken-plugin --skip-plugins --skip-themesloads WordPress without them, so the bad plugin can be switched off.
When none of those fit, --debug on the failing command shows each bootstrap step and every PHP notice. The last step printed before the error shows where loading stopped.
Download task-based WP-CLI references, safe scripts, backup-first examples, configuration, and a pre-flight checklist.
FAQs on WP-CLI Commands
What is WP-CLI?
WP-CLI is the official command-line interface for WordPress. It manages core, plugins, themes, users, the database, cron and multisite networks from a terminal, using the same WordPress code wp-admin runs.
How do I see every WP-CLI command?
wp help lists every command available on the site, including commands that plugins add. wp help plugin install shows every option for one command.
Can I use WP-CLI on shared hosting?
Yes, when the plan includes SSH access. Many hosts preinstall WP-CLI, and wp --info confirms it. Without it, the Phar file can live in your home folder with a shell alias.
Does wp plugin update --all put the site in maintenance mode?
Yes. WP-CLI turns maintenance mode on while it updates and off when the updates finish. If an update is cut off and the site stays in maintenance mode, wp maintenance-mode deactivate turns it off.
What is the difference between wp transient delete --expired and --all?
--expired removes only transients past their expiry, which is safe housekeeping. --all removes every transient, so plugins rebuild their cached data on the next requests.
How do I write a custom WP-CLI command?
WP_CLI::add_command() registers a command from a plugin or mu-plugin. It accepts a closure or a class, and WP_CLI::success() prints the result line.
How do I update WP-CLI itself?
wp cli update updates a Phar install, and wp cli version confirms the result. Homebrew and Composer installs update through those tools instead.
Final Remarks
If the terminal still feels risky, we'd start with the commands that only read: wp option get home, wp plugin list and wp db size --tables. From there, we'd add one write command at a time, each with a fresh wp db export before it.
Once those feel routine, the update sequence above is the one we'd turn into a script first.



