The Girl With the Dragon Tattoo knows how to use Terminal, and that's cool

Profile picture for user Tom
Tom Fleming
Senior Developer

In David Fincher’s latest film, The Girl With the Dragon Tattoo, audiences can see something that Web developers do almost everyday: grep. The goth-punk hacker heroine Lisbeth Salandar’s chosen method to search for patterns in a set of files is the same Unix command-line text-search utility that developers use.

Showing real, modern programming and command-line usage on the silver screen isn’t a new concept, but it is rare. For anyone who saw The Social Network, which is also a David Fincher film, the Mark Zuckerberg character writes actual PHP code on the screen, but outside of those two films, cinematic programming typically looks like this scene from Hackers:

Hack the Gibson

Watching fantastical scenes like this one can be excruciating when you know that the images on the screen are so out of touch with reality. The Girl With the Dragon Tattoo, however, doesn’t disappoint in its technological representation, and that small touch of realism goes a long way toward suspending your disbelief a little longer.

With that said, if you’re using Linux or Mac OS X, it is not too difficult to grep like Salander. This tutorial will be geared toward Mac OS X users.

First, you will need a file with some text to search. You can use Mac OS X’s native text editor, TextEdit, which can be found in the Applications folder, but downloading a third-party text editor, such as TextWrangler, is highly recommended. You can download TextWrangler here.

After opening your chosen text editor, type or copy and paste the following:


Save the file on your Desktop as thingslost.txtNote: If you are using TextEdit, you should set the file format to Plain Text at the prompt.

Next, you will need to open Terminal, which can be found by typing ‘Terminal’ in Spotlight, that small magnifying glass located at the upper-right part of your screen.

When Terminal opens, type the following command:

grep -n sock ~/Desktop/thingslost.txt

You should see something like:


The number next to the word, which is added by using ‘-n’ in the grep command, indicates the line number in the document where that word can be found. To understand what that all means, in TextEdit, use Command + L, and type the line number. You should be taken to the word, which is on the second line of the document. In TextWrangler, the line number is indicated to the left of the type-able area.

For developers, one purpose of grep is to easily locate specific code in lengthy documents. Commands in grep can become more complicated, searching lengthier documents and whole directories for complex patterns, making it a far more powerful tool than the typical search options found in many applications: an obvious choice for someone like Salander.

comments powered by Disqus