Contact Us

Use the Terminal

Posted on 9/9/08 by Felix Geisendörfer

Hey folks,

here is a word of advice if you want to have more fun developing. Use the terminal. Windows user? Make your next machine a mac (or install linux).

Ever since I switched from Windows to OS X in last July, I have been working on my bash skills on and off. Every step of the way I learned tricks that save me valuable time on a daily basis now. Now it just simply hurts to watch people who avoid the terminal work. Take creating a new database and importing some sql into it. The typical GUI workflow for this is:

  • Open a MySql client (PhpMyAdmin, Navicat, ...)
  • Click somewhere to create a new database
  • Type in the db name (mouse -> keyboard switch)
  • Click somewhere to get an import sql dump dialog, often this is hidden in sub-menu (keyboard -> mouse switch)
  • Browse to the location you need to find your file
  • Select the file and hit enter
  • Sometimes now you have to confirm the import again
  • Done

If your sql file is compressed and your client doesn't support that compression you will even have to manually uncompress the file somewhere along the way. My typical experience from watching people going through the GUI way of sql import is that it takes them 5-10 minutes.

Now lets look at the bash side of things.

  • Cd into the directory with the sql file
  • Run the following commands:
mysql -e "CREATE DATABASE foo;"
bzcat foo.sql.bz2 | mysql foo

As you can see, the terminal way of doing this is a lot more efficient. Not only that, your also usually have less problems with it. Because the further you get away from the terminal the more tools and applications are usually stacked on top of each other to make for a GUI app. That usually leads to more bugs and slowness. Especially importing large sql files (I used to import ~2-3gb of data on a regular basis for a client) is something where GUI apps have failed me big time in the past.

Another big advantage of doing things in the terminal is that you can replay them easily. Any decent terminal will or can be brought to record the history of the commands your enter. Check out your shells history commands. If what you did fails, you can easily try again by executing one of your previous commands again without having to type it in (arrow key up). Using a GUI you will have to manually go through all the steps involved again.

Here is another command I use a lot - emptying a CakePHP app's cache directory:

find app/tmp -type f | xargs rm

Anyway, my point is not that everything should be done in Terminal. In fact, for most things I like to have a GUI. But anything that looks like something you might end up doing a lot or that you are likely to do a lot more if it wasn't as much of a pain as it is right now - consider figuring out how to do it in the terminal.

-- Felix Geisendörfer aka the_undefined


You can skip to the end and add a comment.

Frank said on Sep 09, 2008:

Cheers for the command to empty the cache. I've started using the command line a lot more too, some of the most handy commands I use are !! which is to use the previous command. So if you forget to sudo some command you can: sudo !!. And $_ which accesses the last argument of the previous command. So if you cp /from/here /to/here and then cd $_ you go straight to the dir you copied into.

Felix Geisendörfer said on Sep 09, 2008:

Frank: Yeah those are neat. I forgot to link to in the post which is also a great article on this stuff.

Christian Winther said on Sep 09, 2008:

find app/tmp -type f | xargs rm
Is the same as:

1) find app/tmp -type f -delete


2) find app/tmp -type f -exec rm {} \;

but quite faster (1 being faster and easier)

Brian said on Sep 09, 2008:

I've been using Ubuntu for development for the past few years and I can vouch for what you're saying. The bash shell *IS* my "IDE."

Gustavo Carreno said on Sep 09, 2008:

Hey Felix,

I know that most of you guy forget cygwin[1] just because it's for a lesser OS when you guys go off of it.

I'm a Linux lover that's a bit stuck on Windows for the moment, but one thing that I really can't get by is the lack of a shell. And I mean a GOOD shell, cuz the cmd.exe is just a looser.
That's why cygwin is my choice when I have to work under windows.

It's easy to install, easy to upgrade and with just a little more effort you can have a rxvt terminal with a bit more than the 80x25 of a DOS window.

It just rock if you miss your bash love ;)


[1] http://www,

Felix Geisendörfer said on Sep 09, 2008:

Christian Winther: I like xargs because its much more flexible with other commands I pipe find into (git rm for example).

Gustavo Carreno: cygwin is better than nothing, but copy & pasting sucks and so do a few other things that come with not really being in a *nix environment.

Frederic Bollon said on Sep 10, 2008:

Hi Felix
I agree with you, command line is often faster and in addition, when the command is not easy to remember, I create a shell script and an alias.

For example, to ignore in Subversion the content of tmp folders when I start a new CakePHP project, I use a script like this :

svn propset svn:ignore "*" app/tmp/cache/models/ app/tmp/cache/persistent/ app/tmp/cache/views/ app/tmp/logs/ app/tmp/sessions/ app/tmp/tests/

I create an alias in my .bash_login :
alias svnIgnoreCakeTmpFiles='sh /Users/fred/scripts/'

So, in my new project folder I only run "svnIgnoreCakeTmpFiles"

Frederic Bollon said on Sep 10, 2008:

To be able to use the new alias, don't forget to execute the command :
source .bash_login

Kevin van Zonneveld said on Sep 13, 2008:

Hi Felix, there is another way to search through your bash history than repeatedly pressing the up-arrow. Try pressing CTRL+R and start typing any part of a previous command.

It's like a SELECT * FROM history WHERE command LIKE '%${felix_bash_input})%'

And just hit enter when it displays the right command. Saves a LOT of time once you get the hang of it.

PS Ubuntu nowadays makes for a very slick desktop & powerful workstation at the same time. No need to wait for a 'next mac' in my eyes.

Felix Geisendörfer said on Sep 13, 2008:

Kevin van Zonneveld: Holy shit! This is awesome! And if I press CTRL+R multiple times I can get to all previous matches! Thank you so much for this!

James Collins  said on Oct 03, 2008:

Kevin: Thanks for the tip about ctrl+R. I didn't know about it.

I used to do a "history | grep searchterm" to find the command in the history then run it with !xxxx.

ctrl+r is definitely a lot easier.

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.