Every wordpress user loves wordpress’ admin interface. Entire wordpress installation can be managed in one interface. Plugin installation, configuration, updates etc can all be managed from one single interface. What if there is a command line interface for the WP admin functions? That is what exactly provided by WP-CLI. Users with shell skills will love this tool.

WP-CLI is a command line tool for managing wordpress installation. Plugin, Cache, User Capabilities, Comments, Database, Media, Menu, Posts, Theme, Widgets can be managed using this tool. WP-CLI works even in a multi-site WP installation.

WP-CLI comes as a one single binary file which you can save to a location like /usr/local/bin/wp. One installation is enough to manage multiple wordpress installed in a server.

Installing WP-CLI

Download the wp-cli.phar package.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Run to test if it works.

php wp-cli.phar --info

Make the file executable.

chmod +x wp-cli.phar

Move wp-cli.phar to /usr/local/bin/wp

mv wp-cli.phar /usr/local/bin/wp

Updating WP-CLI to latest version

To update wp-cli, execute

wp cli update

Sample use-cases

It is always safe to run wp-cli with the user-privilege. Do not run as root.
WP-CLI checks the current working directory for wordpress installation. So either you have to change directory to the wordpress installation folder or use the --path argument to provide the path to the wordpress installation.

To get a list of plugins installed in wordpress.
wp plugin list

To update a plugin

wp plugin update <plugin-name>

To list all comments

wp comment list

To check if a wordpress update is available

wp core check-update

Export WP database

wp db export

Search and replace strings in WP database

wp search-replace <old_string> <new_string>

To list themes

wp theme list

To update theme

wp theme update <theme_name>

WP-CLI comes with good documentation. Check out http://wp-cli.org/commands/ for full list of commands.