Skip to content

Working with the Command Line and WP-CLI

When we think about “using a computer,” we usually think in terms of graphical user interfaces, or GUIs: interfaces (like Microsoft Word, the Mac OS, or the WordPress admin interface) that are specially and attractively designed, that have programs and windows and tabs that visibly open and close, and that let you click things and drag things and drop things and hover things.

For some development tasks, the command line is still both significantly faster and more powerful than any GUI tool.

It wasn’t always this way. The original manner of interacting with a computer is through the terminal, also called the command line: a stripped-down, usually mouse-free interface for entering programming commands directly.

Well, the terminal’s not just a piece of history. For some kinds of tasks, the command line is still both significantly faster to use and more powerful than any GUI tool that exists. This is especially true for a WordPress developer, thanks to one of the coolest pieces of programming ever to hit the WordPress community: the WP-CLI project, which hugely simplifies all kinds of WordPress tasks—everything from “delete the 100 oldest comments” to “update all plugins” to “export the entire database.”

This 9-part course is a gentle and thorough introduction to the magical world of the terminal, and to the hypermagical world of WP-CLI.

Let’s dive in!

🚀 Start Learning

Over these 9 lessons, you’ll move from command-line basics to confidently using WP-CLI to manage and streamline your WordPress development workflow. Here’s what you’ll learn, step by step:

🎥 A quick note about videos: Some lessons include videos recorded when the course was first launched in 2017. While the tools shown and the WordPress interface may look different today, the underlying principles remain the same. The written content in each lesson is kept up to date.

  1. What is the Command Line? CLIs from First Principles
  2. Navigating the Filesystem from the Command Line
  3. The Basics of Manipulating Files from the Command Line
  4. 10-ish Unix CLI File Commands Every WordPress Developer Should Know
  5. Mastering the Unix Terminal: Working With Permissions, Networking, and Other Key Concepts
  6. How and Why to Make a Bash Alias
  7. The What, How, and Why of WP-CLI: WordPress in Your Terminal
  8. Installing WP-CLI
  9. Anatomy of a WP-CLI Command: wp database import

🛠️ Useful Resources

Here are some helpful resources to go further with WP-CLI.

Wrapping Up

This course should offer you an accessible introduction to one of a serious developer’s most powerful tools—the speed, simplicity, and directness of the command line—and to the WordPress superpowers of WP-CLI specifically. Thanks for reading, and we’d love to hear thoughts or questions in the comments below!

Fred Meyer
Share:

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Tom Dana
June 7, 2017 7:51 am

Great command line information. I use the command line for many of the commands you mention in the article. My question is when you do WP-CLI specific commands like ‘wp plugin update –all’ do you have to be in a certain directory? What if you are on a shared server with multiple domains with WordPress installed? Do you have to be in ‘plugins’ directory to do the ‘wp plugin activate plugin-slug’ command?

-David Dumonde
June 7, 2017 2:51 pm
Reply to  Tom Dana

Tom, WP-CLI operates on the directory that you are in. If you keep your WP sites in /var/www/html and you have two sites /wp1 and /wp2, cd to the wp1 directory and all WP-CLI commands will apply to that site. Then cd to the wp2 directory and all WP-CLI commands will apply to the second site. No need to cd to /wp-content/themes or /plugins to run WP-CLI commands on themes or plugins.

-David Dumonde
June 6, 2017 6:06 pm

Fred and David:

You guys produce some really great content. I’m moderately competent on the *nix command line, but I’m still finding my way around WP-CLI, though I’m loving it.

My question is probably beyond the scope of these articles, but I thought I’d ask if you could point me in the right direction. With WP-CLI, is it possible to perform actions on a subset of posts. Just as an example, can I use WP-CLI commands to do something like: get all posts where fred is the author and change the author to david, or get all posts where the post status is pending and the post date is in May and set the post status to published. Thanks for any help you may be able to offer.

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!