Stephan Spencer's Scatterings

The Scattered Wisdom of a scientist turned web marketing virtuoso

January 2009
S M T W T F S
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

My Favorite Command Line "Hacks" - for Power Users (Geeky!)

I'm on a Mac and I love working from the command line (i.e. from within the Terminal or iTerm). Here is a random collection of some of my favorite "hacks" (time-saving tips and tricks), which will also work not just on Mac OS X, but in Linux/Unix distributions such as Ubuntu and with whatever shell you prefer (bash, csh etc.)...

(Please note: I've assumed you have Perl installed and in your PATH. If you don't know what I'm talking about, these tricks are not for you, and you'll probably do some damage. You have been warned. :) )

Search and replace within a file - without launching a word processor!

Hypothetical example, replaces all occurrences of "chicken" with "fish" in a text file called somefile.txt and saving a back-up (just in case!) to somefile.txt.bak:

perl -pi.bak -e 's|chicken|fish|g' somefile.txt

Real-world example, using regular expressions. Replaces all dates in a dd/mm/yy (British date) format in a Quicken QIF file (that I downloaded via online banking from a bank in New Zealand) with American date format mm/dd/yyyy for use in the American version of Quicken:

perl -pi.bak -e 's|(\d\d)/(\d\d)/07$|\2/\1/2007|g' download.qif

Another advanced example, that takes all the .html files in the current directory and strips out anything that was commented out using comment tags, i.e. <!-- -->...

perl -pi.bak - 0777 - e 's|<\!--.*?-->||gs' *.html

Rename a bunch of files in a directory - in batch!

This example renames all files in the current directory ending with .jpeg so they end with .jpg instead:

for i in *.jpeg; do; mv $i `echo $i|sed 's/jpeg/jpg/'`; done

Backticks (`) are amazingly powerful. With them you can execute commands and have the output of that command get used in another command. Yep, nested! Awesome!

Batch resize images

This example creates thumbnail images of all the .jpeg files in the current directory, each being no bigger than 400 pixels in either dimension, and the height-width aspect ratio is kept intact (i.e. the image is not stretched). Each thumbnail filename is prepending with the word "small", followed by the original file's filename (e.g. from lolcat.jpeg to smalllolcat.jpeg):

(Note that this hack requires you to have the ImageMagick package installed, which includes the very handy "convert" command. To check whether ImageMagick is installed, type "which convert", then if nothing turns up, try "locate mogrify" (I didn't suggest "locate convert" because that would probably turn up a lot of other apps and files besides ImageMagick's convert). The easiest way to install ImageMagick on the Mac is to download a precompiled binary pkg file.)

for i in *.jpeg; do; convert -geometry 400x400 $i small$i; done

(Tip: This is especially handy for when you want to upload a bunch of images to Flickr but don't want to waste bandwidth and time uploading the high-resolution originals.)

Batch convert the image format on a bunch of files

This one takes all the .jpg files in the current directory and creates .png files out of them. You could alternatively convert pngs to jpegs, gifs to jpegs, jpegs to gifs, gifs to pngs, etc. etc. Each filename has the same base as its counterpart (e.g. from lolcat.jpg to lolcat.png).

(Note that this also requires ImageMagick.)

for i in *.jpg; do; convert $i `echo $i|sed 's/jpg/png/'`; done

Examine the type of redirect (301 or 302) on a URL and where it leads - great for following a chain of redirects!

Sure, you could do this with the livehttpheaders extension but I don't use Firefox, I use Safari 'cuz it's so blazingly fast on the Mac compared to Firefox or even Camino.

(If you don't know why you should care about which type of redirect you're using or whether it's a long chain of redirects, you'd better read my Search Engine Land article: Redirects: Good, Bad & Conditional.)

Here I'm looking at the hypothetical example URL of www.example.com...

(Note that you don't need to use a properly formed URL beginning with http://.)

lwp-request -Sd www.example.com

Don't forget to put the URL inside of quotes if the URL is a dynamic one with question marks and ampersands (or other special characters). Like so:

lwp-request -Sd "http://example.com/search?q=cheese&num=20"

More likely than not, you don't have lwp-request installed already. If that's the case, it's easy to install LWP, it's just a CPAN library. Install it like so:

sudo cpan install LWP
Enter "no" when prompted whether you are ready for manual configuration.
Then hit the Return key a bunch of times

If it can't find your "make" program, you can configure it like so, using whatever your path is to make (in the example below I've assumed /usr/bin):

perl -MCPAN -e shell
o conf make /usr/bin/make
install LWP

Back up your MySQL database to a SQL file - especially before running a WordPress upgrade!

I've used the hypothetical database name of "databasename" in the example below:

mysqldump -udba -p databasename > databasename.sql

Consider adding this command to your crontab if you want to have regularly scheduled database backups (crontab -e for that).

Back up your folders using rsync

Sure, if you're a programmer you probably live your life within a version control system like Subversion (svn). And so for you it will be trivial to put your important documents in a Subversion repository and under version control. But I don't live and breath svn. I know enough to be dangerous - and I intend to keep it that way! (I practice Tim Ferriss' philosophy of "selective ignorance".)

If you're lucky enough to own a Mac, just buy a Time Capsule and be done with it. But for the rest of you, you can use rsync to remotely sync (back up) your computer.

Here's an example of backing up your Documents directory onto a remote server:

(Note: This assumes you've set your domain name using "domainname" or you have "Search Domains" in your Network settings set to your local domain name. Otherwise use the full hostname with the domain name in the following command, e.g. eeyore.netconcepts.com instead of just eeyore.)

rsync --force --ignore-errors --delete-excluded --delete -av -z -e ssh ~/Documents root@eeyore:/home/stephan

Here's an example of how you can back up your mail folder from the mail server onto a local backup drive:

rsync --force --ignore-errors --delete-excluded --delete -av -z -e ssh root@eeyore:/home/stephan/mail /Volumes/BackupDrive

View the code in a binary file

Strings shows only the text that can be extracted from the binary file. I use it when I don't want to launch Microsoft Word (a memory hog that takes 30 seconds to start up on my machine) but I want to quickly view a Word document's contents, like so:

strings something.doc

If I need to examine the data within a binary file, byte by byte, I use od (stands for octal dump) rather than strings. Like so:

od -c something.exe

od is also handy for examining the ASCII codes of strange characters in a HTML page, like so:

lwp-request http://shop.bellacor.com/results-13/70/1.htm | od -c

History repeats itself

I use the up arrow key all the time to pull up previous commands so I can revise them and reissue them. Once the chosen command is displayed, I can use backspace, delete, etc. to change it. An even better way to do it is to use the ^ operator if you simply want to swap out one word for another, like if you made a typo.

For example, if the previous command entered was a typo:

covert -geometry 200x200 big.png small.png

Then you could correct that simply by typing:

^covert^convert

Cool eh!

I love referring back to my history and re-using previous commands. Sometimes I want to scan all my history, for that just type:

history

Another huge timesaver is the exclamation point. But do yourself a favor and refer to it as the "bang" operator. So if you were to spell out out !con to your geek friend over Skype, you would say: "bang c-o-n". That'll make you sound like you're in the inner sanctum of all geeks. ;)

Here's how it works... Bang followed by a number executes the command at that specified line number in your history output. For example:

!127

Bang followed by letters executes the command in your history that begin with the specified letters. So if I wanted to rerun the last ping command I ran a while ago, I'd just type:

!ping

Or if I'm extra lazy I might type:

!pin

I wouldn't type !p because I could accidentally issue an unintended command if I had forgotten I had used more recently and that also happened to start with a p.

What about QuickSilver, you ask?

If you're a Mac power user, you're probably using QuickSilver and getting big productivity gains from it. Well good for you! I myself don't use it that much, primarily just for launching applications. But I plan to use it a lot more. I just have to get myself into that habit. If you're a Mac user and want to learn more about QuickSilver, the best introduction to it (imho) is this video of Merlin Man demonstrating it on MacBreak. I don't see the bash shell (Terminal) and QuickSilver as mutually exclusive. Really they go hand-in-hand.

Posted by Stephan Spencer on 09/09/2008 | Permalink

Comments (3)| Comments RSS | Filed under: Programming , , , , ,            

Productivity Tips from the Master: This You Gotta Hear

Does this sound familiar?... No matter how well you plan your day, the day seems to get away from you and at the end of it you never seem to finish all of the tasks you anticipated finishing? This is the story of my life! It feels out of control. Thankfully there's a way out - it's called "GTD" (Getting Things Done), a time management, or more appropriately, life management methodology developed by best-selling author David Allen. This methodology is outlined in great detail in Getting Things Done, which is one of my all-time favorite business books.

Recently I had the distinct pleasure of sitting down with David Allen for a fascinating discussion. I asked him for solutions to the problems that still plagued me, despite being an enthusiastic student of GTD (I've written about GTD on multiple occasions).

David gives some some excellent answers on how to...

  • eliminate time-stealing distractions,
  • how avoidance affects success,
  • how crisis negatively impacts your ability to think intelligently,
  • how sometimes waiting until the last minute is the best way to get things done,
  • the importance of emptying your email inbox,
  • the usefulness of virtual assistants,
  • and how the biggest barrier to self-expression and self-actualization is our own selves.

"You can't manage time," David said. "You actually only manage what you do during time. So the management issue is not so much about time, it's more about how you manage your focus, how you manage your actions and your activities in terms of what you do. That's one of the problems with that whole field of time management -- they mislabel the problem. Because they label the problem as time, everyone thinks that the calendar is going to be your solution, and it isn't."

In a deadline-driven, time-sensitive, stress-filled world, having the right strategies to deal with your myriad of responsibilities is essential to avoiding burnout and remaining permanently productive. With some elements of your professional life, David's advice is simple to apply, such as merely paying attention to what has your attention. With other things, you may find yourself facing off against tightly-held, self-destructive habits and behaviors that will prove difficult to disown.

Check out the podcast audio MP3 and read my article about the interview published this week on MarketingProfs.com.

Posted by Stephan Spencer on 04/12/2008 | Permalink

Comments (1)| Comments RSS | Filed under: General , , ,            

Web 2.0 productivity

One of the most inspiring sessions at Web 2.0 Expo last week was "Mastering the Low-Information Diet" by entrepreneur Tim Ferriss. Tim is author of the book The 4-Hour Work Week. (Yes, it's true, he spends only 4 hours per week running his 2 businesses.) The session was part of the "Ignite" evening of lightning-round 5-minute sessions. Tim's presentation was voted by the audience (using cell phone voting via SMS) as one of the best sessions of the night and was thus included in the keynote on Day 3 of the conference. So I got to enjoy Tim's 5-minute "drinking from a firehose" talk -- twice! It's amazing what a speaking pro can do with a mere 5 minutes! Here are my notes from the session:

Tip #1: "Selective ignorance"
We're in a world of infinite interruption and infinite minutia. Practice "selective ignorance" -- you don't need to know and follow everything.

Tip #2: "Batching"
Batching is performing similar tasks at set times. You only do these tasks at specific times and in the meantime you let them accumulate.
For example, check your email only twice a day. Use an auto-responder to let urgent issues get picked up sooner. Example of auto-response message: "Dear esteemed colleagues, In order to get more done, I'm checking email only twice per day -- once in the late morning and once in the late afternoon. If you require a response sooner than that, please call my cell phone at 555-555-5555."

Tip #3: Pareto Principle
Focus on the "critical few," not the "trivial many."
You may ask "What if i miss something important?" Tim responds that he's never missed anything that cost him more than $500.00. Whereas, by practicing this, he has gained millions of dollars in additional booked revenue.
"Pareto Principle" is the 80/20 rule. For example, 20% of the people in your business life will consume 80% of your time. Not all customers are created equal. 5% of your customers may contribute 95% of your profit. Figure out which customers are not profitable and "fire" them. Tim fired the worst offenders and put remaining lower-profitability customers "on auto-pilot" -- never proactively contacting them or thinking about them.

Tip #4: Outsource your life
Tim has between 20 and 40 MBAs around the world that he outsources various aspects of his business and personal life to, such as: database creation / prospect list creation, etc... Even online dating!
Find people to outsource your life to on GetFriday.com (7 day trial), Elance.com, etc.
If you can pay someone half or less of what you earn per hour and they can do a reasonable job of it, outsource it!

Tip #5: Schedule life in advance
It's not about "work-life balance," it's about "work-life SEPARATION".
If you have a void, you'll fill it with work. So fill your schedule with personal activities too, not just business activities.

Read Tim's blog for more of his wisdom.

Watch his talk at Ignite

Posted by Stephan Spencer on 04/26/2007 | Permalink

Comments (6)| Comments RSS | Filed under: General            

Getting organized - a progress report

On January 1st on the MarketingProfs' Daily Fix where I am a contributing blogger, I proclaimed my New Year's Resolution to the world -- which was to implement an amazing system for unprecedented gains in productivity and organization that I had discovered. That system -- called GTD by its followers -- is based on the best-selling book Getting Things Done by David Allen. With GTD, you stop using your brain as a holding tank for all the important things that you need to do and remember, so that you can be in the state of flow -- what Allen calls "Mind like water."

Sound pretty good eh? Well it is. But it's no quick fix; it can take years to really master GTD. There are new processes to learn and old habits to break. It's easy to "fall off the wagon," so to speak, but it's equally as easy to get back on it. To learn more about what GTD can offer, have a read of my MarketingProfs article from a couple weeks ago: Clearing the Clutter - How Busy Marketers Can Get Things Done.

My biggest accomplishment was getting everything and into one place -- into a program called Journler (for the Mac). Trying to keep track of, and make sense of, the cacophony -- the ideas and to do's floating around in my head, the half-written email drafts, the Word documents, scribbled notes on Post-Its and backs of envelopes -- that was fighting for my attention made me feel 'out of control' and caused me a lot of stress. I'm glad to be out of that. Now that I have a central repository to turn to, I'm never going back to my old way of recording things!

Allen's "two minute rule" has been a big time-saver and sanity saver. The rule says: "If it can be done in 2 minutes or less, then just do it right then and there rather than defering it to later." I used to touch the same email over and over again, even though it would have been a less than two-minute task to deal with it. What a time killer that was! I don't do that quite so much any more.

One thing I haven't totally licked yet is my overflowing email inbox. That's next on my list. Allen advises maintaining an "Inbox Zero" state. I'm reading Merlin Mann's excellent article series on the topic, which is giving me some great tips and tools. I can't wait to learn how to do "email triage." Mann claims anyone can clear their inbox in less than 20 minutes using the approach he outlines.

I'm still struggling with (learning about) managing projects with GTD. Even "Next Actions" are giving me some trouble. Next Actions are easy to manage when you have a manageable number. However I currently have 134 Next Actions. Probably that's too many and I should move some into "Someday/Maybe". With so many, even filtering those by context (e.g. "Errands", "Calls", "Writing") still leaves me with an overwhelming list.

With that said, being able to view these to do's by context has made me more efficient, because it empowers me to do stuff in batches, such as phone calls when I'm in a phone mood or when I have dead time while in the car or sitting in a waiting room.

Also, having a "Waiting For" list has freed my mind a bit because I don't have to retain the fact that certain people owe me responses or deliverables. I simply review my Waiting For list, which triggers me to send out reminder emails to people who still owe me stuff.

So, there you have it. Far from perfect, and only scratching the surface of GTD, but it's a start and I'm certainly better off than I was last year because of it. Overall I'm pretty pleased with my progress.

Any of you, dear readers, using GTD? Or thinking about it?

Posted by Stephan Spencer on 02/15/2007 | Permalink

Comments (5)| Comments RSS | Filed under: General , , , ,