Updating Drupal core from the Linux command shell

If you want to easily update Drupal core, then this is right for you. This approach will first compare your deployed Drupal with the original Drupal source code to do a pre-update sanity check. Then the old Drupal files are deleted one by one, the empty directories as well, and then the new Drupal is deployed.

If you follow this approach, updating your Drupal core version should take you less than 5 minutes.

If you have no shell access to your hosting provider, you can still apply the approach described in this article if you have a mirror copy (a perfect replica) of the deployed Drupal server on a host you have shell access to. Apply the changes on the mirrored files on your local host (steps 1 to 5, skip step 6), then synchronize the changes with the webhost, and finally run update.php (step 7).


As usually, you are strongly recommended to create a proper backup of your Drupal installation and of the database prior to any upgrade. Failing to do so may ruin your Drupal site. You have been warned.

Make sure you replace all smart quotes (‘’ and “”) with straight quotes ('' and "") when copying/pasting the instructions in a command shell.

Updating Drupal core

Step 1: open a terminal window on your server

Use your preferred terminal application, or log on your server and open a console. I'm pretty happy with PuTTY.

Step 2: check the Drupal version you're currently running

In Drupal 6, go to yourdrupalsite.yourdomain.com/admin/reports/updates. In this post I'm assuming we're upgrading from version 6.13 to 6.15.

Step 3: get Drupal

Create a working directory for the update process, and download the Drupal tarballs for (1) the version you're currently running and (2) the version you want to install.

$ mkdir -p ~/work/drupal/core
$ cd ~/work/drupal/core
$ wget http://ftp.drupal.org/files/projects/drupal-6.13.tar.gz
$ wget http://ftp.drupal.org/files/projects/drupal-6.15.tar.gz
$ for i in drupal*.tar.gz ; do tar xfz $i ; done

You now will have 2 directories, each containing one Drupal release.

Step 4: compare deployed with origina Drupal code

In this step we'll check whether we edited the code from Drupal core at some point in time. You may have decided to apply a patch or to tweak something. If so it's not always possible to update Drupal core, as you will need to understand what you changed before attempting the update.

The following check will verify whether your currently deployed Drupal version differs from the original Drupal version we downloaded in step 3. I'm assuming Drupal is deployed in /var/www/html/drupal:

$ cd ~/work/drupal/core/drupal-6-13
$ find . -type f -exec diff -u "{}" "/var/www/html/drupal/{}" ';'

If you changed something, then this command will display the changes. If you see changes, do not proceed with the update until you carefully reviewed the changes.

If this command prints nothing, then this means that you did not touch the original Druapl core. Your upgrade should be pretty safe and uneventful.

Step 5: update Drupal core

We will first delete every single file (line 2) and then also delete every empty directory (line 3 - depth-first find!) from the original Drupal release (assuming version 6.13 here):

$ cd ~/work/drupal/core/drupal-6.13
$ find . -type f -exec rm "/var/www/html/drupal/{}" ';'
$ find . -depth -type d -exec rmdir "/var/www/html/drupal/{}" 2&>/dev/null ';'

Now we will recreate the directory structure (line 2) and inject the files from the new Drupal release (line 3) (again assuming version 6.15 here):

$ cd ~/work/drupal/core/drupal-6.15
$ find . -type d -exec mkdir -p "/var/www/html/drupal/{}" ';'
$ find . -type f -exec cp -p "{}" "/var/www/html/drupal/{}" ';'

We now have an updated Drupal core file base. Now we must update the database to finalize the update.

Step 6: reset file and directory ownership

Check the user and group that own the web server files:

$ ls -ld /var/www/html/drupal

It is possible that you may have to check the root of the webserver. This usually is /var/www/html but it may be in a different place. What matters here, are the 3rd and 4th item returned by the ls command: they represent the owner and the group of the directory. Example output may look like:

drwxr-xr-x 9 apache apache 4096 Feb 13 15:29 /var/www/html/drupal

In this case, the user is apache and the group is apache. Now we reset the file ownership so the web server process can handle the Drupal files again:

$ chown -R apache /var/www/html/drupal
$ chgrp -R apache /var/www/html/drupal

Step 7: update the Drupal database

In Drupal 6, go to yourdrupalsite.yourdomain.com/update.php. Launch the update process. If you see no errors, the Drupal update was a success.

Olivier Biot's picture

If you have no shell access...

You can still apply the approach depicted in this article if you have no shell access to your hosting provider. All you need is a replica of your deployed website (files only) on a local machine where you have shell access. This can either be a Linux, *BSD or UNIX box, or a computer running MS Windows with a Linux-like enironment (Cygwin or Unxutils). The former is mostly Linux compliant where the latter may require some command-line edits (quotes most notably).

The procedure you should follow in this case, is:

  • Step 0: Create a mirror (replica) of your deployed website (this procedure only needs the files) on a local machine.
  • Perform steps 1→5 on this local machine.
  • Skip step 6.
  • Synchronize the new local files with your hosted website files.
  • Perform step 7.
Andrea's picture

works! typo in step 5: $ find

typo in step 5:
$ find . -depth -type d -exec rmdir “/var/www/html/drupal/{}” 2&>/dev/null ‘;’
‘;’ did not work for me, instead use ';'

Olivier Biot's picture

Re: typo in step 5

Thanks for spotting this typo!
I should disable the typogrify module - it replaced straight quotes with smart quotes. The same error can happen at other places the procedure depicted in my article above.

meganox's picture

Thanks for the post. I like

Thanks for the post. I like to do the diff in the other direction:
$ cd /var/www/html/drupal
$ find . -type f -exec diff -u "{}" "~/work/drupal/core/drupal-6-13/{}" ';' > diff.changes 2> diff.added
Then diff.added gives you a list of all the files in your site which aren't in core so you know exactly what you need to restore

Paolo's picture

Great help, thanks!

Great help, thanks!

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.