Tag Archive: workflow

Save Time with sed

When I develop WordPress sites, I find that I end up repeating many identical tasks for each site. The phrase “repeating identical tasks” should (and does) set off alarms: This should be automated! To that end, I’m trying to learn some more command line tools for doing tasks that I currently use a GUI for.

One such task is migrating my development database to the staging/production server. Basically a mysqldump from my local database that I can then import on another server. A key thing to watch out for with WordPress, though, is the base URL for your site. If you’re serving a site from localhost while you develop it, you’ll need to change every occurrence of localhost in your database to the base URL for the new server.

sed is a command line tool for doing just that job. It runs a regular expression search on the input and outputs the replacement. Example:

$ echo "localhost" | sed "s/localhost/www.example.com/g"

Pipe your mysqldump through sed to have an SQL file ready for your new server.

$ mysqldump -uusername -ppassword database_name | sed "s/localhost/www.example.com/g" > database.sql

This way I avoid having to open the SQL file in a text editor, doing a global search and replace, and re-saving.

Find Files by Size

Find all TIFFs in a directory smaller than 90 MB:

$ find /dir/to/search -name *.tif -size -90M -exec ls -lh {} \;

Get just the size and path and write to a file:

$ find /dir/to/search -name *.tif -size -90M -exec ls -lh {} \; | awk '{print $5 , $8}' > output.txt

Useful for finding images that might have been scanned at the wrong resolution/bit depth/etc.