View the blog post & comments about this session

Drupal runs on *nix servers, it helps to know how to use them
Non-developer with dev skills = Productivity Boost
some macro some micro
some basic some advanced
some sophisticated some ghetto
I hope everyone will learn something & then we can share our own tricks
We're mostly self-taught or learn through human osmosis ∴ we can all learn from each other.
Going thru everything fast, but will all be
@ http://benbuckman.net/hacks
"cmd fu: The art of doing battle with the command line" (UrbanDictionary.com)
Works natively on all non-Windows OS's (Unix, Linux, Mac OSX)
cd, mkdir, ls. current dir (pwd)| pipe>, >> outputVARIABLE="VALUE", $VARIABLE; to separate lines/commandsaliasman help docshistory, !999 past commands, re-run specific command!! re-run last command, e.g. sudo !!& run as background process&&, || chain commands
$? last exit code (0=success)cat full outputhead toptail bottom
tail -f follow: e.g. for log-n# number of linesmore paginatedOutput stdout to file:
script.sh > script.log
script.sh 2&> script.log
script.sh 2> error.log(and good output goes to screen)
output to oblivion: dont-wanna-know.sh > /dev/null
stdout is zero-sum, tee is stdout+file
export EDITOR=nanofindfind . -name "*.module"find . -size +1024k-maxdepth, -mindepthfind . -type d -name ".svn" -exec rm -rf {} \;find /var/backup/ -name "*.sql.gz" -type f -mtime +21 -exec rm {} \;man findfor
for VAR in $LIST; do SOMETHING; done;while
while CONDITION; do SOMETHING; done; (generic)
LIST | while read VAR; do SOMETHING; done;while vs for -- line break treatment:

find+while:
find . -name "*.module" | while read MODULE; do
drush pm-enable `basename $MODULE .module` -y
done
grepBasic text search: grep -r "some text" .
grep is slow)awk alternative
A few flags:
-i case-insensitive-v exclude Look for all ubercart modules:
drush sm | grep -i uc
find . -name "*.module" -exec grep -i "_form_alter" {} \;grep "_form_alter" $(find . -name '*.module')
grep "_form_alter" $(find . -name '*.php' -or -name '*.inc' -or -name '*.tpl')wc, count lines: wc -l
find . -name "*.tpl.php" | wc -l
if [[ `find . -name "*.tpl.php" | wc -l` -gt 100 ]];
then echo "Jeez you have a lot of templates!"; fi
File/dir size: du, du -h -s *
du -k -s * | sort -n | tail -n1Free space: df
ln -s FILE LINK
Group commands with {}:
{ echo "hello"; echo "goodbye"; } | cat
Backup (zipped):
tar -czf /var/backup/site.zip /var/sites/site
tar --exclude=PATTERNzip SQL dumps:
mysqldump | gzip -c > dump.sql.gz
gunzip -c | mysql
(same -c, different meaning)
rsync for file transfers (local & remote)
rsync -rC to avoid SVN-plAdd to /etc/hosts:
echo "echo \"\n127.0.0.1 local.site\" >> /etc/hosts" | sudo sh
Identify variant of *nix:
uname -a (Linux kernel version)lsb_release -a (distro information)cat /etc/issue (more basic info)ssh: use keys instead of passwords (ssh-keygen)
Automate/schedule anything with cron
function svnurl() { svn info $1 | egrep '^URL: (.*)' | sed s/URL\:\ //; }
svn diff $(svnurl prod)@HEAD $(svnurl dev)@HEADalias svnaddall='svn status | sed -ne "/^?/ {s/^? *//;s/ /\\\ /g;p;}" | xargs svn add'alias svnrmmissing='svn status | sed -ne "/^\!/ {s/^\! *//;s/ /\\\ /g;p;}" | xargs svn rm'alias svnnew='svn st | grep -e "^[!M?~ACDR ]"'dl, endrush cc all
Make sure you correctly added a hook in your module:
drush hook theme_status_messages
Calculate the size of your database:
DB_NAME=`drush sql-conf | grep "database" | awk '{print $3}'` drush sql-query "SELECT table_name, (data_length+index_length)/1024/1024 'Size_MB', data_free/1024/1024 'Free_MB' FROM information_schema.TABLES WHERE table_schema='${DB_NAME}' ORDER BY table_name;" <!-- `drush sql-query "SELECT table_schema 'DB', sum(data_length+index_length)/1024/1024 'Size_MB', sum(data_free)/1024/1024 'Free_MB' FROM information_schema.TABLES WHERE table_schema='${DB_NAME}' GROUP BY table_schema;" ` -->
drush features-update-all -y, drush features-revert-all -y --forcedrush ...declare language: #! /bin/bash, #! /usr/bin/env bash
make sure file exists:
if [ ! -f $SOMEFILE ]; then
echo "Missing file $SOMEFILE"; exit
fi
make sure drush exists:
if [ ! `which drush` ]; then echo "Missing Drush!"; exit; fi
Catch errors by chaining: command && command && command || { echo "Error."; exit; }
Simple/clunky way to compare changes between 2 DBs
RewriteEngine On <!--## set env vars for domains ## dash indicates no subst ## '.*' is critical!! thanks http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html ## no commas between flags!--> # siteenv = local, live, dev RewriteCond %{SERVER_NAME} localhost RewriteRule .* - [E=siteenv:local] RewriteCond %{SERVER_NAME} ^site.com$ [OR] RewriteCond %{SERVER_NAME} ^www.site.com$ RewriteRule .* - [E=siteenv:live] RewriteCond %{SERVER_NAME} ^dev.site.com$ RewriteRule .* - [E=siteenv:dev]
getenv('siteenv')Spotlight for math (built-in)

AppleScript
Skitch
Clyppan
open
namespace :drush do set :webroot, "#{deploy_to}/current" set :drush_cmd, "drush --root=#{webroot} --uri=#{drush_uri} " def drush_intro logger.info "Running drush with root=#{webroot} and uri=#{drush_uri}" end # status/info task :drush_status do drush_intro # hide the DB password logger.info capture "#{drush_cmd} status | grep -v \"Password\" " end
Chrome Search Drupal extension

Firebug for Drupal (Firefox & Chrome)
ConnectBot on Android
