by Ryan Irelan
In the last blog post we covered the basics of bash aliases and how to create one. This time I want to jump back into Greg’s Command Line Fundamentals course and share a nice trick on how to automate downloading and extracting the latest version of WordPress.
This is an alias we could use just about every single day.
I have an empty directory on my computer called
new-wp. I want to create an alias that will:
Here’s what the alias would look like:
alias get_wp="wget http://wordpress.org/latest.tar.gz && tar zxvf latest.tar.gz && rm latest.tar.gz"
The first part is using the
alias keyword to start defining a new alias, followed by the name of the alias. In this example we’ll call it
Then we define the commands, starting with
wget, fetching the
latest.tar.gz file on the WordPress server, which always contains the latest version of the software.
We use the
&& operator to tell Bash to run an additional command (but only when/if the first one completes). The second command is to unarchive the file using
Finally, we add another
&& operator to remove and bash the downloaded archive. Since we’ve already unarchived it, we no longer need it around.
Now run the command inside the
and see the magic happen!
If you prefer to watch instead of read, check out this excerpt of the same tutorial from Greg Aker’s Command Line Fundamentals course: