Commands

Useful Drush Commands

Technologies: 

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.

Useful DB Queries for Drupal Applications

Show grouped node counts based on OG group ids for nodes created after a particular time stamp

select gid, count(*) from og_membership inner join node on og_membership.etid = node.nid and node.created >=  1678127400 group by gid;

Show node type specific node count list

select type,count(*) from node group by type;

Show group membership wise node counts

Optimizing Images using command line

The images uploaded by users may not be of ideal size and may require compression to manage server space. There are some tools available for compressing JPG and PNG files.
Please note that the owner changes to the current username for the file after compression. Please remember to change ownership if required of the file or per folder post compression.

jpegoptim :
Optimize a jpg image with the same name

jpegoptim image.jpg

Optimize all jpg images in a folder

Keyboard Key bindings in Ubuntu

Technologies: 

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

Technologies: 

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

Technologies: 

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

<?php