Text interface to interact with computer
Less visual feedback than a GUI *
More expressive than a GUI
* Graphical User Interface
point - click,
point - click,
point - click
$ wp user set-role alain admin↵
Success: Added user (1) to http://wp.test as admin.
$ _
1 minute of work
1 minute of work
point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click, point - click,
...
$ wp site list --field=url | xargs -n1 -I %
wp --url=% user set-role alain admin↵
Success: Added user (1) to http://wp.test as admin.
Success: Added user (1) to http://1.wp.test as admin.
Success: Added user (1) to http://2.wp.test as admin.
Success: Added user (1) to http://3.wp.test as admin.
...
6.9 days of work
5 minutes of work
The shell prompt is the entry point where you can type your commands.
$ _
Just enter the name of the application:
$ <name-of-program>↵
<output-of-program>
$ _
⇒ magic stuff will happen!
-a, --all
show hidden entries-l
use a long listing format--all
== -a
-a -l
== -al
.
current directory..
parent directory-
previous directory~
current user's home directoryIf current text only results in 1 match, that match is used.
If current text results in more matches, available options are shown. Reduce set by typing additional characters and try again.
Write programs that do one thing and do it well.
Write programs to work together.
Write programs to handle text streams, because that is a universal interface.
Combine small, sharp tools and the use of a common underlying format — the line-oriented, plain text file — to accomplish larger tasks.
<cmd1> ; <cmd2>
run cmd1
, then run cmd2
<cmd1> && <cmd2>
run cmd1
, on success run cmd2
(logical AND)<cmd1> || <cmd2>
run cmd1
, on failure run cmd2
(logical OR)
~ $ mkdir dir1 && cd dir1 && mkdir dir2 && cd dir2 && echo "Success!"↵
Success!
~/dir1/dir2 $ _
Input"one two"
Commandwc
Output2
echo "one two" | wc -w
Command 1
Command 2
<cmd1> | <cmd2>
use output of cmd1
as input for cmd2
~ $ ls -1 *.php | wc -l↵
42
~ $ _
echo Current folder is <XYZ>.
=> Current folder is <XYZ>.
pwd
=> /Users/alain
echo Current folder is pwd
.
=> Current folder is /Users/alain.
<cmd1> $(<cmd2>)
use output of cmd2
as argument to cmd1
~ $ echo "Currently in folder $(pwd)."↵
Currently in folder /Users/alain.
~ $ _
Mix-and-match commands to get the result you need.
Install additional tools if the provided ones are not sufficient.
Simplify workflows and automate work by building custom scripts.
Mix-and-match custom scripts to build entire automated systems.
Shell script: text file with one or more shell commands that are executed in a linear order.
Comment: piece of text that will not be executed and can be used to leave notes.
Shebang: Comment in first line of script to let the shell know about the interpreter to use.
File my-first-script.sh
:
#!/bin/sh
# This is a comment.
# Run two commands in sequence.
echo "Hello World!"
echo "How are you doing?"
File my-first-script.sh
:
#!/bin/sh
# This is a comment.
# Run two commands in sequence.
echo "Hello World!"
echo "How are you doing?"
$ my-first-script.sh↵
Hello World!
How are you doing?
$ _
WP-CLI is the official command line tool for interacting with and managing your WordPress sites.
Goal: Fastest way to do anything with WordPress
Refer to the handbook, which starts with the section Installing .
wp help
General help screen with a list of commands *wp help <command>
Help screen for a specific command* The output might run through a "pager" like more
to let you paginate. Hit q
to exit that pager.
--path=<path>
Path to the WordPress files--skip-plugins[=<plugin>]
Skip loading all or some plugins--prompt[=<assoc>]
Prompt the user to enter values for the arguments--quiet
Suppress informational messages--debug[=<group>]
Show all PHP errors and verbose bootstrap outputwp cli info
Print details about the WP-CLI environmentwp cli update
Update WP-CLI to the latest releasewp package list
List installed WP-CLI packageswp package install <package>
Install a WP-CLI packagewp package uninstall <package>
Uninstall a WP-CLI packagewp package update
Update all installed WP-CLI packageswp core
Manipulate a WordPress installwp db
Perform basic database operationswp plugin
Manage pluginswp theme
Manage themeswp media
Manage attachmentswp post
Manage postswp user
Manage userswp comment
Manage commentswp scaffold
Generate code for various componentswp search-replace
Search/replace strings in the databasexargs <command>
Split input into multiple calls to <command>
~ $ wp cap list 'editor' | xargs wp cap add 'author'↵
Success: Added 24 capabilities to 'author' role.
~ $ _
editor
and then pass these on to the next command to add these capabilities to the role author
.
Sites $ wp core download --path=newsite↵
Creating directory '/Users/alain/Sites/newsite/'.
Downloading WordPress 4.7.4 (en_US)...
md5 hash verified: eefcac6dcb954183fff27e5998d62b5f
Success: WordPress downloaded.
Sites $ cd newsite↵
newsite $ wp core config --dbname=newsite --dbuser=root↵
Success: Generated 'wp-config.php' file.
newsite $ wp db create↵
Success: Database created.
newsite $ wp core install --url=newsite.dev --title="New Site"
--admin_user=mr_robot --admin_email=ea@evilcorp.com↵
Admin password: bAgvzQlmNsYY
Success: WordPress installed successfully.
newsite $ _
newsite $ wp core update↵
[ ... ]
Success: WordPress updated successfully.
newsite $ wp plugin update --all↵
[ ... ]
Success: Updated 4 of 4 plugins.
newsite $ wp theme update --all↵
[ ... ]
Success: Updated 1 of 1 themes.
newsite $ _
newsite $ wp media regenerate --yes↵
Found 2 images to regenerate.
1/2 Regenerated thumbnails for "cropped-Banner.png" (ID 15).
2/2 Regenerated thumbnails for "Banner" (ID 14).
Success: Regenerated 2 of 2 images.
newsite $ _
1. Join make.wordpress.org Slack team:
https://make.wordpress.org/chat/
2. Join the #cli
channel
I'm Alain Schlesser.
Follow me on Twitter:
@schlesseraOr visit my Personal Blog:
www.alainschlesser.com