Some quick background: Regular computer users access the computer via a graphical user interface (GUI). This interface allows you to interact with the machine using a mouse and images on your screen to make the computer do what you want.
But you can also navigate and control your computer by using text-based commands on something called the command line. By firing up a program called Terminal (at least on Mac), you can enter text commands and navigate through your computer.
Noah Veltman, a 2013 Knight-Mozilla Fellow at BBC News, led a session at MozFest called “Solve A Murder Mystery on the Command Line." The game involved a folder of .txt files with thousands of lines. To solve the murder mystery, we had to search through the files using the command line to pull out specific phrases.
After channeling my inner detective during the session, it occurred to me that I didn’t know how to use the command line until a couple months after I started programming. Once I started using the command line, I understood my machine much more and learned programming more quickly.
I talked to Noah after the session to gather a couple more ideas on why journalists should learn the command line.
It makes it easier to work with text data
When it comes to working with text data, especially large and messy files, command line tools are your best friends. Datasets might come to you as .csv files from a government agency, or as .txt files from local companies. To navigate through these files or to extract useful and interesting information the command line helps you do so quickly.
You might wonder, Why not just open Excel or Access to look at the data? While Excel works great with a 50MB file, the software isn't nearly as nimble with a 5GB file. By way of example, Illinois School Board School Scorecard files include more than 10,000 columns and precious little metadata to explain what’s contained in each one. The big and complicated files are very hard to comprehend and it turns out to be a challenge to analyze the data.
With the command line, a couple basic commands will help you analyze text data:
The cat command allows you to read the files. It opens a text file and prints the content in terminal. Type the word cat followed by a space and the name of the file.
grep option pattern filename
The grep command is used to search text for specific patterns. For example if I would like to search for the word “corgi” in a file called corgi.txt. I would enter the command:
grep “corgi” corgi.txt.
head option filename
The head command reads the first few lines of any files. For example if I would like to look at the first 20 lines of a file I would enter the command:
head -n 20 corgi.txt
It lets you use tools built just for journalists
Tons of tools built for journalists involve using the command line, if only during the installation phase. You’ll often hear that “software package X is exactly what you need" for a particular task, but then you wind up looking at a GitHub repo where you learn that installation of that software involves various command line operations.
csvkit, for example, converts files to .csv and helps you to clean up and standardize data. Using csvkit and the command line, you can filter a .csv down to a subset of columns, search and filter rows, join various .csv files, etc. These tasks are done by simple commands like
csvgrep, etc. As opposed to copying and pasting from one Excel file to another, these short commands allow you to clean and organize your data in a matter of seconds.
It’s a gateway to full scripting languages
Noah referred to command line tools as “a gateway drug” to actually learning a full scripting language like Python. Once you begin to feel comfortable with a few basic commands, you can begin to combine them in all sorts of ways to get what you need even if you cannot write a custom data processing script.
There are plenty of reasons to learn the command line. Hopefully your curiosity is sparked. If it is, click the links below to learn more: