Easy WP-CLI Commands For WordPress Maintenance

Bulletproof Backups for Your WordPress Website

Fortify your business continuity with foolproof WordPress backups. No data loss, no downtime — just secure, seamless operation.

wp-cli commands

Learning the right WP-CLI commands can save you a lot of time on tedious tasks. It helps you manage your entire WordPress site through a simple text interface. Repetitive tasks take mere seconds.

This guide is your practical cheat sheet. We’ll skip the theory and give you the exact commands you need to get started today. 

TL;DR: WP-CLI commands let you perform actions on your WordPress site with simple text commands. However, it’s a direct line to your site’s core files and database, and there is no “undo” button. So, use a backup plugin  that takes automatic backups in the background. 

Prerequisites for WP-CLI Commands

So, what is WP-CLI and how do you get started? It’s tempting to jump straight into running commands, but that’s like trying to perform surgery without scrubbing in first. This section covers the three prerequisites you must have in place before you use WP-CLI commands.

  • Secure Shell (SSH) Access: To use WP-CLI, you first need to connect to your server’s command line by running the SSH command ssh username@yourdomain.com in your terminal, using the credentials provided by your host. A basic understanding of SSH is a great bonus. 
  • Full Site Backup: WP-CLI commands are powerful, and with great power comes the ability to instantly break things. There is no confirmation pop-up and no quick way to backtrack. This is why you need a recent, reliable backup of your entire site.
  • WP-CLI Installed on Your Server: This might sound obvious, but the WP-CLI software must be installed on your server for you to use it. If you manage your own server (like a VPS or dedicated machine), you may need to install it yourself. You can always check with your host’s support team to confirm it’s available.

Cheat Sheet of Essential WP-CLI Commands

Now for the part you came for. This section is your go-to WP-CLI commands cheat sheet, designed to give you the most impactful commands without the fluff. We’ve broken them down into logical groups, from managing your core files to handling plugins and users, so you can find exactly what you need to get the job done quickly.

Navigate Your Server

Before you can run a single WP-CLI command, you have to be in the right place. The command line requires an understanding of your WordPress file structure and how to move between them. 

1. Find Out Where You Are

pwd

How to use it?
Simply type pwd (which stands for Print Working Directory) and press Enter. The command line will immediately show you the full path of the directory.

2. See the Contents of Your Current Directory

ls

How to use it?
Run ls to see a simple list of all visible files and folders in your current location. 

3. Move Between Directories


cd

How to use it?
cd (which stands for Change Directory) is always followed by where you want to go.

To move into a folder, type cd followed by the folder’s name (e.g., cd public_html). To return to your home directory from anywhere, just type cd by itself.

4. Reference Your Current Directory

.

How to use it?
The single dot (.) is a universal shortcut that always refers to your current directory. For example, if you have a script in your current directory, you might run it with ./myscript.sh. The ./ part explicitly tells the system to run the script found in the current folder.

Move Up to the Parent Directory

..

How to use it?

The double dot (..) WP-CLI command is your “go back” or “move up one level” shortcut. It always refers to the parent directory of your current location.

WordPress Core Management

Updating your WordPress installation is one of the most critical tasks for site security and performance. These commands let you install, update, and verify your core files directly.

1. Download the Latest WordPress Files

wp core download

How to use it?
Navigate to an empty directory on your server where you want your new site to live. Run the command as is. It will automatically install WordPress and unpack the files into that folder.

2. Install a New WordPress Site

wp core install --url=<yourdomain.com> --title="<Your Site Title>" --admin_user=<username> --admin_password=<strongpassword> --admin_email=<youremail@example.com>

How to use it?
After downloading the core files, run this WP-CLI command. You must replace all the placeholder values (like <yourdomain.com> and <username>) with your actual site information. This command configures your database, creates your first admin user, and brings your site online.

3. Update Your WordPress Core

wp core update

How to use it?
Navigate to your existing WordPress site’s root directory. Simply run this command, and WP-CLI will automatically update your site to the latest stable version of WordPress. It’s the command-line equivalent of clicking “Update Now” in the dashboard.

4. Check Your Current WordPress Version

wp core version

How to use it?
From your WordPress site’s root directory, just type the command and press Enter. It requires no extra information and will instantly show you the exact version number of your installation.

Plugin and Theme Management

Managing plugins and themes is a daily reality for any WordPress site owner. Instead of clicking “update” a dozen times or navigating multiple screens to find and activate a new addon, you can do it all from one place. 

1. Install a Plugin from the Repository

wp plugin install <plugin-slug>

How to use it?
Replace <plugin-slug> with the official slug of the plugin from the WordPress.org repository (e.g., woocommerce or akismet). This command downloads and installs the plugin onto your site in one step.

2. Activate an Installed Plugin


wp plugin activate <plugin-slug>


How to use it?
After installing a plugin, use this command to activate it. Just like before, replace <plugin-slug> with the plugin’s official name. This is the command-line equivalent of clicking the “Activate” button.

3. List All Your Plugins

wp plugin list

How to use it?

Run this command as is from your WordPress directory. It will generate a clean, organized table showing every plugin on your site, its status (active/inactive), and its current version number.

4. Update All Plugins at Once

wp plugin update --all

How to use it?
This is one of the biggest time-savers in WP-CLI. Simply run this command to update all of your outdated plugins in a single go. No more clicking one by one.

Expert advice: We do not recommend you do this without testing the updates on a staging site

5. Activate a New Theme

wp theme activate <theme-slug>

How to use it?
Replace <theme-slug> with the folder name of the theme you want to activate (e.g., twentytwentyfour). This command instantly switches your site’s active theme.

6. Update All Themes at Once

wp theme update --all

How to use it?
Similar to updating plugins, this command checks all your installed themes for available updates and applies them. It’s the most efficient way to keep your themes secure and up-to-date.

Database Operations 

Your WordPress database is the heart of your website; it stores every post, page, user, and setting. The following wp-cli database commands are incredibly powerful for tasks like migrations and backups. 

1. Export Your Database for a Backup

wp db export my_backup.sql

How to use it? 

You can replace my_backup.sql with any filename you want. Running this command will export your database and create a complete .sql file of your entire database in your WordPress root directory. It’s an excellent way to create a quick, manual database backup before making a major change.

2. Import a Database from a File

wp db import my_backup.sql

How to use it? 

This command will completely overwrite your current database with the data from the specified .sql file. Make sure the file (e.g., my_backup.sql) is located in your WordPress root directory before running the command. This is extremely useful for restoring a backup or migrating a site.

3. Find and Replace Text in Your Database

wp search-replace '<old-text>' '<new-text>'

How to use it?
This is one of the most essential commands for WordPress migrations. Replace <old-text> with the text you want to find (like http://olddomain.com) and <new-text> with the text you want to replace it with (like https://newdomain.com). WP-CLI will intelligently handle serialized data, which prevents your site from breaking—a common issue with WP-CLI find-and-replace.

4. Optimize Your Database Tables

wp db optimize

How to use it? 

Run this command as is. It performs the equivalent of the “Optimize Table” SQL query on all the tables in your database. This can help reclaim unused space and may slightly improve the performance of your database.

User Management

Creating users, resetting passwords, and managing roles through the WordPress dashboard can be slow and repetitive. These wp-cli user commands streamline the entire process, making it fast and simple to manage user accounts, especially when you’re locked out or need to make changes in bulk.

1. Create a New User

wp user create <username> <email> --role=administrator

How to use it?
Replace <username> and <email> with the new user’s information. The –role flag is optional but useful for setting roles like administrator, editor, or subscriber upon creation. WP-CLI will automatically generate a secure password and email it to the new user.

2. List All Users on Your Site

wp user list

How to use it?
Just run the command from your WordPress directory. It will output a clean table with the ID, username, display name, email, and roles for every user on your site.

3. Reset a User’s Password

wp user update <username> --user_pass='new-strong-password'

How to use it?
This is a lifesaver. Replace <username> with the user’s login name and ‘new-strong-password’ with the new password you want to set. This is the fastest way to regain access to an account when a client (or you) gets locked out.

General Maintenance Commands

Beyond the major categories, WP-CLI is packed with commands that solve common, frustrating WordPress errors. Think of these wp-cli examples as your go-to toolkit for quick troubleshooting and maintenance tasks that often cause headaches when done through the admin interface.

1. Clear Your Site’s Cache

wp cache flush

How to use it?
Run the command as is. If your site uses a persistent object cache (like Redis or Memcached), this command will clear it completely. It’s often the first thing to try when your site is showing outdated content or behaving strangely.

2. Reset Your Permalinks

wp rewrite flush


How to use it?
Run this command as is. This action regenerates your WordPress .htaccess file with the correct permalink rules. It’s the instant fix for the classic problem where newly created pages or posts result in a “404 Not Found” error.

3. Manually Run Scheduled Tasks (Cron Jobs)

wp cron event run --all


How to use it?
Simply run this command to trigger all pending WordPress cron jobs. This is useful for forcing scheduled events that haven’t run yet, such as scheduled posts, backup plugin schedules, or automated update checks.

Essential Best Practices

WP-CLI is a sharp tool; it’s incredibly effective in the right hands but can cause a lot of damage if handled carelessly. Simply knowing the commands isn’t enough. Adopting a few key habits will separate you from the amateurs and ensure you’re using the command line to solve problems, not create them. These are the non-negotiable rules we follow to stay safe and efficient.

Always Have a Backup

If you remember only one thing, make it this: always backup your site with WP-CLi or a plugin before running any command that changes files or the database. There is no “undo” button in WP-CLI. A single typo in a wp search-replace or wp db import command can instantly break your entire site. A reliable, recent backup is your only safety net.

Test on a Staging Site First

Your live, traffic-generating website is not the place to experiment. Professionals create a staging site—an exact clone of the live site on a private server—to test anything risky. Before running a complex database migration or a major plugin update on your live site, practice on the staging site first. This allows you to work out any issues without affecting your users.

Use the –dry-run Flag for a Preview

Double-Check Your Directory Before You Run

Many servers host multiple WordPress sites. It is dangerously easy to accidentally run a command in the wrong site’s directory. Before you hit Enter on any command, get in the habit of running pwd (print working directory) to confirm you are in the correct folder for the site you intend to modify. This simple check can prevent a world of hurt.

When in Doubt, Ask for Help

Final Thoughts

WP-CLI is a transformative tool that separates amateurs from pros. But its power demands respect. The most critical step before running any command isn’t on the command line—it’s securing a reliable backup. Use a one-click solution like BlogVault to ensure you always have a safety net before you begin.

FAQs

What are WP-CLI commands?

WP-CLI commands are text-based instructions that let you manage every aspect of your WordPress site directly from a server’s command line. Think of them as shortcuts that bypass the visual admin dashboard. Instead of clicking buttons to update a plugin, you simply type a command like wp plugin update <plugin-name>, saving time and allowing for powerful automation.

What are the commands used in CLI?

While there are hundreds of commands, most day-to-day work is done with a handful of essentials. The most common commands are used for:

Core Management (e.g., wp core update)

Plugin & Theme Management (e.g., wp plugin update –all)

Database Operations (e.g., wp search-replace)

User Management (e.g., wp user update to reset passwords)

These form the backbone of an efficient WP-CLI workflow.

How to create a WP-CLI command?

Creating a custom WP-CLI command is an advanced topic for developers. It involves writing PHP code, typically within a custom plugin, to register your own command using the WP_CLI::add_command() function. This allows you to automate unique workflows specific to your site or product. For a detailed guide, the official WP-CLI documentation has a “Commands Cookbook” that walks developers through the entire process.

How to run a CLI command?

Running a WP-CLI command involves four simple steps:

Connect to Your Server: Open your terminal and log in via SSH using a command like ssh username@yourdomain.com.

Navigate to Your Site’s Folder: Use the cd command to move into your WordPress root directory (e.g., cd public_html).

Type the Command: Enter the WP-CLI command you want to run, such as wp core version.

Execute: Press the Enter key to run the command.

Tags:

You may also like


How do you update and backup your website?

Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.

Updating Everything Manually?

But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.

Backup Your WordPress Site

Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.