Drush Usefull Commands

These are some of the drush commands that can be used with druapl 7

Count the modules

drush pml --type=module --status=enabled | wc -l

Lists all non core enabled modules

drush pml --no-core --type=module --status=enabled

Lists all enabled core modules

drush pml --core --type=module --status=enabled

Lists all disabled non core modules

drush pml --no-core --type=module --status=disabled

List all disabled core modules

drush pml --core --type=module --status=disabled

List all themes

drush pml --type=theme

List modules with available updates

--core --no-core can be specified here as well.
drush pm-updatestatus

Update core drupal

sudo drush pm-update projects drupal 7.44

These same commands can be combined with some useful Linux commands to document the outputs into text files. This will write the module's machine name into the txt file. For more details run man cat on your terminal.

drush pml --no-core --type=module --status=enabled --pipe | cat > enabled_noncore_modules.txt
drush pml --core --type=module --status=enabled --pipe | cat > enabled_core_modules.txt
drush pml --no-core --type=module --status=disabled --pipe | cat > disabled_noncore_modules.txt
drush pml --core --type=module --status=disabled --pipe | cat > disabled_core_modules.txt
drush pml --type=theme --pipe | cat > themes.txt
drush pm-updatestatus --pipe | cat > modules_to_update.txt

Run cat <filename> to output it on terminal. Example "cat list.txt". The --pipe argument is quite useful in providing a piped output to use in the following command.

Disable all non-core modules is quite easy. Disabling from a list of modules on the other hand may seem a bit more complex.

Disable all non-core modules

drush pml --no-core --type=module --status=enabled --pipe | xargs drush dis -y

Disable all modules from a text file

drush dis -y $(cat modules_list.txt) //OR
cat > modules_list.txt | drush dis -y

The same can be applied for enabling

Update all modules from a text file

drush pm-updatecode $(cat modules.txt) //OR
drush dl -y $(cat modules.txt)

The command "drush pm-updatestatus" works only in versions above 6. It is recommended to update to a version above this. You can find a simple global installation for latest version of drush here.

Drush provides the capability to write nested commands as seen earlier and so does Linux commands. You can mix and match with various commands.

drush en -y $(drush pml --no-core --type=module --status=enabled --pipe)
drush en -y $(drush pml --no-core --type=module --status=enabled --pipe | xargs cat > module_list.txt)

Exporting importing db using drush

drush sql-dump > ~/my-sql-dump-file-name.sql

Download db

If the sql dump file is on a remote server, you can use this terminal command to download a copy of the sql file:

scp tyler@example.com:~/my-sql-dump-file-name.sql ~/Desktop/

Import Database You can use this command to import the sql dump back into your drupal database.

drush sql-drop drush sql-cli < ~/my-sql-dump-file-name.sql

Drop all tables on db

drush sql-drop