Upgrade wordpress quickly in 3 easy steps from UNIX shell prompt

Wordpress Logo

Since I use wordpress as CMS for 2-3 different websites, upgrading wordpress is an essential task for me. Upgrading wordpress from shell prompt is the easiest thing.


Howto update wordpress

Please note that if you are not comfortable with UNIX shell prompt (IF YOU ARE new to UNIX/Linux), please follow traditional way of upgrading wordpress and DO NOT use following instructions 😉

Step # 1: Backup existing database and wordpress directory

Type the following commands at shell prompt:

$ mkdir /backup/wp/28nov2006
$ mysqldump -u user -p WP-DATABASENAME > /backup/wp/28nov2006/blog.db.sql
$ tar -zcvf /backup/wp/28nov2006.tar.gz /var/www/html/blog

Step # 2: Download latest wordpress CMS

$ cd /tmp
$ wget http://wordpress.org/latest.zip
$ unzip latest.zip

Step # 3: Overwrite all new files

$ cd /var/www/html/blog
$ cp -avr /tmp/wordpress/* .
$ rm -rf /tmp/wordpress /tmp/latest.zip

Open a browser and run update script such as http://yourblog.com/wp-admin/upgrade.php

And you are done. Thanks to UNIX shell access. It just took less than 1 minute!!! Replace path names and database name with actual values.

In case, if something goes wrong, you can always restore old database and files from /backup/wp/28nov2006 directory.

PS: I wrote this because some one recently asked me how to upgrade wordpess from command line.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

13 comments… add one
  • Igor Nov 28, 2006 @ 8:15

    hey, you cloned my script i wrote recently! 😉

    little sidenote: tarballs (.tgz) are smaller than zipfiles… but that doesn’t matter these days.

    have fun!

  • MichaelB Jan 7, 2007 @ 3:42

    Thanks, this worked perfectly and saved me a huge amount of time.

  • Chris Mar 5, 2007 @ 3:13

    Be very careful with this method. Since it is basically overwriting existing files with new ones etc it is NOT removing depreciated files which may or may not have security holes in them.

  • Life focus pro Mar 5, 2007 @ 15:48

    Yes, it sounds very fast and easy. I just wish I had access to the schell.

  • fak3r Aug 6, 2007 @ 16:14

    Thanks for the script, I’ve changed it to make it more generic, can be run via command followed by the instance name of your site’s directory.

    # Modify these variables for your system
    # Do not modify these variables
    DATE=`date +%Y.%m.%d`
    # If there's no variable, explain usage and exit
    if [ -z "$1" ]; then
            echo "usage: $0 "
            exit 0
    # Backup existing database and wordpress directory
    mkdir -p ${BACK_DIR}/${INSTANCENAME}/${DATE}
    mysqldump -u root -p ${INSTANCE} > ${BACK_DIR}/${INSTANCENAME}/${DATE}/${INSTANCE}.db.sql
    tar -zcvf ${BACK_DIR}/${INSTANCENAME}/${DATE}/${INSTANCE}.tar.gz ${BLOG_DIR}/${INSTANCE}
    # Download latest wordpress CMS
    cd /tmp
    wget http://wordpress.org/latest.zip
    unzip latest.zip
    # Overwrite all new files and cleanup
    cd ${BLOG_DIR}
    cp -avr /tmp/wordpress/* .
    rm -rf /tmp/wordpress /tmp/latest.zip
    exit 0
  • 🛡️ Vivek Gite (Author and Admin) nixCraft Aug 6, 2007 @ 16:33


    Nice script :D. Few things
    a) change wget http://wordpress.org/latest.zip to
    wget http://wordpress.org/latest.zip -O latest.zip

    b) add little protection before cd ${BLOG_DIR}

    if [ $? -eq 0 ]; then
       cd ${BLOG_DIR}
    cp -avr /tmp/wordpress/* .
    rm -rf /tmp/wordpress /tmp/latest.zip
      echo "Error failed to unzip or download failed"
  • Video Game Sigs May 3, 2008 @ 15:50

    Thanks to this post I was able to upgrade WP on my sites in no time. I dreaded having to wait for the slow ftp process to complete with my sites being down.

    After testing the process on one site and seeing how fast it was, I did not even bother activating the maintenance mode plug in on the other sites. My users tend to get pissed off when the site goes down for a few mins and following the steps you provided prevents this.

    One thing I did before copying over the new WP files to the site, was delete the wp-contents folder from the new WP files. I did not want it over writing what I had in my existing WP-contents folder (plug-ins and themes)

    Thanks again.

  • Wazzup Aug 18, 2008 @ 7:28

    Is there a way to perdform the actual upgrade from the command line as well…

    that is this part: “Open a browser and run update script such as http://yourblog.com/wp-admin/upgrade.php

    • will Jan 30, 2013 @ 10:18

      I think not possible as requires user input

  • Simon J Mudd Jan 7, 2010 @ 13:29

    Handy to know but misses an important point: users and permissions on the server. This can make or break things quite significantly on a box. I’ve found the instructions on what the correct ownership of the wordpress files to be either missing or not clear to me.

    So should ALL wordpress files be owned by the apache user, or perhaps owned by another user with the group set to the group the apache server runs as? That’s what is not clear to me and could be better documented.

  • 🛡️ Vivek Gite (Author and Admin) nixCraft Jan 7, 2010 @ 19:38

    @Simon J Mudd,

    Generally web servers don’t care about file permission as long as they have read permission for a directory. However, before running this go to your blog directory and run the following to see permissions. Note down them:
    ls -l
    Once new file copied just run chown in a blog dir:
    chown -R user:group .

  • blancpain Dec 5, 2010 @ 14:30

    In it something is. Earlier I thought differently, many thanks for the help in this question.

  • n2j3 Feb 11, 2011 @ 9:41

    lifesaver. thanks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.