newline

Table of Contents

  1. The Map and the Language
  2. The GUI and the Command Line
  3. An Example: finding WAV and FLAC files

Why I use the Command Line

Shell, Philosophy

December 28, 2020

The ‘terminal’, ‘shell’, or ‘command line’. It’s an interface that you can easily reach by opening the “Terminal” application on macOS or Linux, but that most people avoid because they view it as “too complicated”, or they aren’t even aware of it. Well, I almost exclusively work on the command line, because it’s actually simpler and much more powerful. I’ll try to explain why, using a navigational analogy.

The Map and the Language

Let’s step away from computers for a moment. Imagine you’re in New York City, for example, and someone asks you for directions from Central Park to Times Square. There are two ways you could handle this.

  1. Using a map. You pull out a map of Manhattan, and say, “well, Central Park is here” (you point to the map). “There are subway stations along the side of the park here (point), so walk to the closest one. Then, take the 2 or 3 train, down to here (point). Get out at Times Square here (point), then walk back up this way (point) and you’ll be there.”

  2. With step by step directions in language. “Walk towards the west of the park, and when you reach the main road outside of the park, look around. If there’s a subway station near you, go inside; otherwise, turn left and follow the main road until you find one. Once inside a subway station, get on the 2 or 3 train, and ride it until Times Square (42nd Street) station. There, get off the train, and walk north (back the way you came) along the main road. Within a few minutes you’ll be there.”

Both methods have advantages and disadvantages. If you use a map, you give the tourist a chance to see an overview of the city. It’s also less verbose (you don’t have to use as many words). The downside is, your directions are useless without a map, or even with a version that looks different. The second method doesn’t give the tourist a visual overview, but can be used even without a map (provided that they know where west and north is, which is easy to figure out - everyone has a compass on their phone now). Also, it’s just text, so it’s flexible; the tourist could even write the directions down and send them to a friend, who could follow them.

The GUI and the Command Line

To tie this analogy back to computers: the map is the GUI (graphical user interface), i.e. the Microsoft Word or Finder or Explorer that you’re used to. You have an overview of what’s going on, and you can point and click to get from your current state (e.g. inside of your Music folder) to the target state (e.g. inside of your Documents folder). You don’t have to use any words, but if the GUI changes, it’ll take you some time to figure it out. Also, there are some things that are just impossible to do with a GUI.

The step by step directions are commands typed on the command line, which are written in the language of the shell, such as Bash. They’re essentially directions that you give to the computer. They are more precise, and you don’t need a specific GUI to use them. They’re just text, so you can easily save them as a file and run them again whenever needed. Or you can send them to a friend, who can run them too. Or post them on the internet — the options are practically endless.

In summary, text commands are much less limiting, more flexible, and more powerful, which is why I prefer using the command line where possible.

An Example: finding WAV and FLAC files

Since this article wouldn’t be complete without an example, I’ll give you one. Let’s say I want to figure out how many WAV and FLAC music files are in my home folder and all subfolders.

In a graphical file manager (à la Finder or Explorer), I would need to find some kind of ‘advanced search’ functionality, search for all files with one extension, remember that number, then search for all files with the other extension, and add those two results together. Or maybe the file manager would let me search for multiple patterns at once. There’s no guarantee that every graphical file manager will have this (or any) type of advanced search built in.

However, on the command line in any UNIX system, I’d just do this:

find /home/alex -name "*.wav" -o -name "*.flac" | wc -l

After a few seconds, I’d get back a single number: the amount of WAV and FLAC files in my home folder. Now, this might look like nonsense if you don’t know shell script, but copy-paste it into explainshell.com and you’re well on your way to learning the command line. Both find and wc are general-purpose commands: find can be used to find any kind of file or folder, and wc can be used to count words/lines/characters in any file. And this command can easily be saved to a file and re-used, which is generally not possible with your typical file explorer.


So, I hope this article has served to show you why the command line can be the better choice, and I hope I’ve at least piqued your interest. If you want to get started on the command line, I’d recommend the Bash manual (man bash in the terminal), the Bash guide on Greg’s Wiki, and Linux Journey.