Drush, a command line for Drupal:Clearing Cache of all Drupal subdomains using Drush

I was working on a project that runs on Apache server that has around 25 + subdomains and run from a single codebase with different databases using Drupal CMS. I needed to clear the inbuilt cache of all subdomains without restarting the server.After searching around. I found a solutions on how to solve this, there is a utility tool named as Drush. It is a command line shell scripting specially built for Drupal. If you do not have drush installed, you can download it from here. Without any assumption,I will take you through the steps in installing drush on a remote server or shared hosting account.

if( OS == Windows)
Download PuTTY and use as your terminal
elseif( OS == Mac || Linux)
You can use the systems own terminal tool

1. Now,you need to have SSH enabled for your shared hosting account.If not,you can request for SSH access for your account from your hosting company.
2. Once you have received SSH access to your site, open a new Terminal and login to your site by typing the following ssh username@yourdomain.com or any additional user login string provided by your Hosting service and Enter your password when prompted.
3. By default, you should be in your home directory .The '~' is an alias for your home directory. On most Linux shared hosting, your website directory is located at ~/public_html or more specifically /home/username/
4. Make sure you are in your home directory by typing the bash shell command ls, which will list the files and folders in the current directory. You should see public_html/, public_ftp, and a bunch of other files. Look out for a file named .bashrc, as we will be editing it later.
5. Download Drush by typing wget http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz, replacing drush-7.x-4.5.tar.gz with the current link. The easiest way to do this is to go to http://www.drupal.org/project/drush and right click on the tar.gz download link, then select "Copy link location" (or the IE equivalent), and simply paste it after wget in the terminal. Hit enter after completing this step, and watch as the command line downloads the tarball to the current directory
6. Next, type clear and hit enter. This will clear your screen, and give you a little more breathing room. Do this as much as you want to throughout this process
7. Now that you have a nice clean screen to work with type ls again, to list your directory
8. Highlight and copy the drush tarball listed
10. Next, run the following command, pasting your tarball in place of the one listed here: tar -xvzf drush-7.x-4.5.tar.gz. Watch as the tarball is unpacked
11. Type ls again to confirm that you now have a folder named drush in your home directory
12. Delete the tarball by typing rm drush-7.x-4.5.tar.gz. Make sure to substitute the tarball listed for the one you downloaded.
13. Next, in order to use Drush across our installation, in all of our subfolders, we need to add a line to our .bashrc file. To do this first confirm you are still in your home folder (cd ~) and then type the following: nano .bashrc. This will open up .bashrc in a text editor named nano. Locate # User specific aliases and functions. Underneath that, add the following: alias drush="~/drush/drush". Save the file by typing ctrl+O. Exit nano by typing ctrl+X.
14. Type source ~/.bashrc to refresh the alias list and allow the new drush commands to work.
15. Confirm that Drush is working by typing drush at the command prompt and hitting enter. You should see a list of drush commands. If you do, then success!
16. If the previous step doesn't work, type exit to end your SSH session, then log back in (See step 2) to restart your session. This refreshes .bashrc and allows the new drush commands to work.
17. You have now added drush hot sauce to your shared host. Awesome!
Please Note:For a more detail documentation and process visit here. The steps above where picked from there.
Now that we have drush installed,we can now test our commands.The below commad clears the cache of all subdomains in one go:
drush @sites -y -r /var/www/ cc all
Here, /var/www the folder path where Drupal is installed.
Other interesting drush commands i will like to share are:
To download and enable a module using drush:
Make sure you navigate into your sites folder then type
drush dl module name (you can leave space if you want to download more than one module or even a theme)
You can also download a module and a theme at once:
drush dl module name theme name module name (this will download the two modules and a theme and place them in the theme and module folder for you.Pretty cool eh!!)
To enable your module:
drush en module name
If you wanted to see the structure of a node or a particular content type just like the way devel outputs its.You can use
drush php-eval 'print print_r(node_load(nid))' and voila!!! you get the node object structure.
In case you're working on a multisite setup you will need to specify the domain or subdomain like this drush --uri=sub.example.com php-eval 'print print_r(node_load(nid))'
If after reading this and you want to learn more and use drush for most of your works/projects,then the Drush Documentation is a place you should look at.
Share