Useful Drush Commands


Log out all active Users:

drush sql-query 'TRUNCATE TABLE sessions;'

Download drupal and rename:
Downloads and renames to web

drush dl drupal --drupal-project-rename=web -y

Install Drupal database:
Installs drupal when executed inside the drupal folder.

Keyboard Key bindings in Ubuntu


My laptop keyboard faced a particular problem with both Ctrl keys not working. It was a hardware issue and only keyboard replacement would resolve. I searched for alternatives where I could replace any key not being used to Ctrl key.

xmodmap is a utility for modifying keymaps and pointer button mappings in Xorg.

To do the same, I replaced the Menu Key in keyboard(keycode = 135) which acts like a right click and mapped it as right control key. To do so, one would need to create the file ~/.Xmodmap and update with the following data.

MySQL handly commands


To prevent duplicate entry issue - replace INSERT into with REPLACE INTO .
DEF: REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.

REPLACE into table (id, name, age) values(1, "A", 19)

Run Optimize of All tables of a database:

mysqlcheck -o db_to_optimize  -udb_user -p

All databases

Drupal Features Update and Revert

Features Update: Update a feature module on your site. This updates the feature module in the site if the components are overriden

drush fu <feature-module-name>

Features Revert: Revert a feature module on your site. Reverts the basic configuration in the module onto the site removing any custom configurations made at the database end.

drush fr <feature-module-name>

Handy Linux Commands


Split: Split a text file in half (or any percentage) on Ubuntu Linux

The following command splits access.log files into multiple files with 6000 lines each

split -l 6000 access.log

Split files into size of 5M each

split --bytes 5M --numeric-suffixes --suffix-length=3 foo.mysql  last_part.mysql

Diff : Get Difference between files and folders
Following command provides recursive difference

Using Drush Alias

drush aliases allow you to run a drush commands on your local server but actually execute the command on a remote server.

One can create aliases in a folder that drush recognizes, mostly inside the .drush folder for Linux Based Systems. For a mysite example, we can create a file called as mysite.aliases.drushrc.php inside the .drush folder (Or any folder which Drush goes through before executing). All aliases in a site can also be combined in a single file called as aliases.drushrc.php

Example data that can be added to mysite.aliases.drushrc.php


Debug you PHP code using DRUSH


Drush is a very handy tool which makes development in Drupal very fast and easy. Almost everyting is JACA("just a command away"). This particualr tip will help you to evaluate your php code using Drush.


Consider a function: ji_custom($node). To evaluate/debug this function I type following in Drush:

drush php-eval "ji_custom($node);"

Aliases for php-eval are: eval, ev

N.B: JACA is invented while writing this post :)

Batch Process Images in Linux

Sometimes its a pain when you want to modify, resize multiple files at once in Linux. Fortunately ImageMagick comes with a handy command called convert that makes the work simpler

Install ImageMagick in Ubuntu

sudo apt-get install imagemagick

Batch Process set of files in a folder and resize them to 1024X768

for file in *.jpg; do convert "$file" -resize 1024x768 "$file"; done

You may also try an app called as phatch for GUI related batch processing of images.

Snippet to bulk rename files by replacing strings in filename