Using WP-CLI Command Line Tools
Last Updated -
All VPS and Enterprise plans come with a powerful command line tool known as wp-cli For an overview of basic commands, open terminal and enter the following.
$ cd ~/sites/domain-to-manage $ wp --help
You should receive the following list.
cache Manage the object cache. cap Manage user capabilities. cli Get information about WP-CLI itself. comment Manage comments. core Download, install, update and otherwise manage WordPress proper. db Perform basic database operations. eval Execute arbitrary PHP code after loading WordPress. eval-file Load and execute a PHP file after loading WordPress. export Export content to a WXR file. help Get help on a certain command. import Import content from a WXR file. media Manage attachments. menu List, create, assign, and delete menus network option Manage options. plugin Manage plugins. post Manage posts. rewrite Manage rewrite rules. role Manage user roles. scaffold Generate code for post types, taxonomies, etc. search-replace Search/replace strings in the database. shell Interactive PHP console. sidebar Manage sidebars. site Perform site-wide operations. super-admin List, add, and remove super admins from a network
Each top-level command has multiple subcommands to use. In order to view all subcommands of a specific command you can use wp <command>
wp plugin --help
This will return the following
NAME wp plugin DESCRIPTION Manage plugins. SYNOPSIS wp plugin
SUBCOMMANDS activate Activate a plugin. deactivate Deactivate a plugin. delete Delete plugin files. get Get a plugin. install Install a plugin. is-installed Check if the plugin is installed. list Get a list of plugins. path Get the path to a plugin or to the plugin directory. search Search the wordpress.org plugin repository. status See the status of one or all plugins. toggle Toggle a plugin's activation state. uninstall Uninstall a plugin. update Update one or more plugins.
Some commonly used wp-cli commands.
$ wp plugin status
Displays your current plugins details showing which are active/inactive and if they have an update available
$ wp theme status
Displays a list of installed themes, your active theme and updates available
$ wp db query
Opens Mysql command line client to interact with the database
$ wp search-replace
Database search and replace, also handles serialized arrays
wp search-replace example (note: please be cautious when using search-replace and make sure to always back up your database first)
$ wp search-replace 'http://old-domain.com' 'http://new-domain.com'
This will update the database replacing http://old-domain.com with http://new-domain.com
The --recurse-objects parameter will handle replacements for widgets and theme options
Nearly all common WordPress functions are available in wp-cli for a full list and updates of new commands that become available you can check the official wp-cli website.
Please view our wp-cli blog post for some extra tips