Skip to content

Instantly share code, notes, and snippets.

@sumanthkumarc
Created August 11, 2016 10:52
Show Gist options
  • Save sumanthkumarc/1459de72862f54237419142d35572454 to your computer and use it in GitHub Desktop.
Save sumanthkumarc/1459de72862f54237419142d35572454 to your computer and use it in GitHub Desktop.
Some Drush commands Drupal
============================================
Using drush to get a list of enabled modules
============================================
If you just wanted to make a list of all the modules which are installed in your instance. Don't waste time, be smart write a command using drush. - See more at: http://drupaltonight.com/drupal-articles/using-drush-get-list-enabled-modules#sthash.b10DQqN5.dpuf
List all modules and themes :
drush pm-list
List only modules :
drush pm-list --type=Module
List all modules except core modules :
drush pm-list --type=Module --no-core
List all enabled modules except those from the core :
drush pm-list --type=Module --no core -- status=enabled
List all enabled modules except those from the core which belong to the CCK package :
drush pm-list --type=Module --no core --package=CCK status=enabled
If you want more info about the pm-list
drush help pm-list
- See more at: http://drupaltonight.com/drupal-articles/using-drush-get-list-enabled-modules#sthash.b10DQqN5.dpuf
========================================================================================
Drush : Set password, watchdog entries and run sql-query
========================================================================================
1. You have a Drupal instance and you don't remember the password for the admin.
drush user-password admin --password="admin123"
converting the password to MD5 and storing it in DB drush will take care :)
2. Recently I had an instance of Drupal to which I was not able to login. I wanted to check out the watchdog entries, but as I was not able to login I had to check it from db. I thought drush may help me out and it did.
drush watchdog-show
For more http://drush.ws/#watchdog-show
You can also use watchdog-list which will give you more control. This throws up a set of options like cc does and you can select what you want
drush watchdog-list
3. If you are drupal developer and you are using, it's a safe bet to assume that you are using sql-cli. But the pain with that is that you need to remove the braces from the table names to actuall run the query.
drush sql-query "SELECT u.name, u.status from {users} u where uid = 1"
- See more at: http://drupaltonight.com/drupal-articles/drush-set-password-watchdog-entries-and-run-sql-query#sthash.KxCdIwXp.dpuf
========================================================================================
Drush : How to quickly enable or disable Drupal CSS/JS optimization using DRUSH
========================================================================================
// To turn on JS Aggregation
drush vset preprocess_js 1 --yes
// To clear all Cache
drush cc all
// To disable JS Aggregation
drush vset preprocess_js 0 --yes
// To clear cache of JS and CSS only
drush cc css+js
// To enable CSS Aggregation
drush vset preprocess_css 1 --yes
// To disable CSS Aggregation
drush vset preprocess_css 0 --yes
========================================================================================
Drush : How to quickly get list of enabled/disabled/not installed modules/themes
which either can be part of drupal core not may not part of drupal core
========================================================================================
1.View the update status of modules
drush -n pm-update
2.Update site modules
drush pm-update
3.Download drush modules
drush pm-download module1 module2 module3
5.Enabling modules
drush pm-enable module1 module2 module3
6.Disabling modules
drush pm-disable module1 module2 module3
7.Download drush to create a new installation
drush pm-download –drupal-project-rename= my.sitename drupal
8.Get the list of enabled (disabled) modules
drush pml --type=module --status=enabled
9.Get the list of and status of a specific module
drush pml --type=module --package="Package Name" (if you know the exactpackage name)
or
drush pml --type=module | grep 'part of package name or module name' (if you are not sure of a package or module name)
***To list modules which are disabled or not installed and not part of drupal core
drush pml --type=module --status="enabled" --type="module" --no-core
***To list modules which are disabled or not installed and not part of drupal core
drush pml --type=module --status="enabled" --type="module" --core
***To list modules which are disabled or not installed and not part of drupal core
drush pml --type=module --status="disabled,not installed" --type="module" --no-core
***To list modules which are disabled or not installed and part of drupal core
drush pml --type=module --status="disabled,not installed" --type="module" --core
***To list modules which are disabled or not installed and not part of drupal core
drush pml --type=module --status="disabled,not installed" --type="theme" --no-core
***To list modules which are disabled or not installed and part of drupal core
drush pml --type=module --status="disabled,not installed" --type="theme" --core
========================================================================================
Drush : User related commands
========================================================================================
//to get information of users
drush uinf 2,3,someguy,somegal,billgates@microsoft.com
//to reset password of existing user
drush upwd pfssuser --password="admin123" pfssuser
//to create new user
drush ucrt newuser --mail="person@example.com" --password="letmein"
//to add role to user
drush urol "power user" 5,user3 --uid=2,3 --name=someguy,somegal --mail=billgates@microsoft.com
//to remove role
drush urrol "power user" 5,user3 --uid=2,3 --name=someguy,somegal --mail=billgates@microsoft.com
//to block users
drush ublk 5,user3 --uid=2,3 --name=someguy,somegal --mail=billgates@microsoft.com
//to unblock users
drush uublk 5,user3 --uid=2,3 --name=someguy,somegal --mail=billgates@microsoft.com
//to cancel user account
drush ucan --delete-content username
//to displays a one-time login link for the user ryan.
drush uli username
//to open web browser and login as user ryan.
open 'drush uli username'
========================================================================================
========================================================================================
@sumanthkumarc
Copy link
Author

for sql dump:
drush sql-dump --gzip --result-file=sites/default/files/file_name.sql

@mohammad-hod
Copy link

mohammad-hod commented Sep 21, 2016

finding cause for WSOD, put this in settings.php:

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

@sumanthkumarc
Copy link
Author

sumanthkumarc commented Nov 30, 2016

clear all cache tables using drush and sql query:
Found at : http://drupal.stackexchange.com/a/196059

Truncate cache tables in MySQL regardless of the active cache backend
echo "SHOW TABLES LIKE 'cache%'" | $(drush sql-connect) | tail -n +2 | xargs -L1 -I% echo "TRUNCATE TABLE %;" | $(drush sql-connect) -v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment