On the merits of Command Line Interfaces
15. 6. 2017

Nicolas König

Linux

To many people, Command Line Interfaces (CLIs) seem to be a relic of a long forgotten past, of a time in which computers could only display green text on black background and floppy disks were the storage medium of choice. Nowadays, colorful Graphical User Interfaces (GUIs) are the standard for most users. But if you look closely, you will come to realize that CLIs are much more than useless toys for people who got a Commodore C64 for their 18th birthday. They are very powerful tools to whoever opts to use them. This article aims to explain their power to you and will hopefully give you a clue where to start. It will concentrate on the Linux standard command line called Bash, since this is the shell I know best. However, most of these tools should be available on Windows as well in some form or another.

→ CLIs are fast

There are two important points to be made: Firstly, easy tasks do not take longer with CLIs and, secondly, complicated tasks are much faster. For example it makes little difference whether you take your mouse and click a folder icon or type "cd dir_to_open", but it starts to make a difference if you look at more complicated tasks. Here are a few examples, increasing in complexity:

1. Count the approximate number of statements (not comments!) in all the C files in a directory
GUI: Search in your IDE whether it has this option. If it doesn't, then sadly enough you are out of luck.
CLI: tr -cd '#;{' < *.c | wc -c
2. Delete all files named foo, bar, or xyzzy in a given directory
GUI: Search for foo, ensure that you only found exact matches, wait for search to finish, delete everything, search for bar etc.
CLI:find -regex '\./\(foo\|bar\|xyzzy\)' -delete
3. Get every file in a directory containing the string "foo" and move them in another directory
GUI: I wouldn't know any way short of opening every file, searching it manually and copying it if necessary
CLI: grep -Rn 'foo' | awk 'BEGIN {FS=":"} {print $1}' | xargs sh -c \ 'for i in $@; do mv $i /path/to/dir; done' {}

→ CLIs don't need many resources

In a time where e.g. Microsoft’s Visual Studio needs sometimes more than 10% of the processing power of your computer just to show the program’s windows, having a tool that only needs miniscule amounts of CPU power and memory is a blessing. At the time of writing, the command line editor I'm using to write this article uses 0.093 percent of the 8 GB of my computer's memory and 0.08% of its CPU.

→ CLIs are easy to use

This might come as a bit of surprise to some, but certain aspects of CLIs are really easy to use, or at least you always know where to find help. The manual is never further than 5 keystrokes away. If you need help with any command, you can just type "man command" and the manual with a lengthy explanation of what the command does - and often even with examples - opens. Also, with most commands, just typing "command --help" will give you a short help text. This gives you a comprehensive and clear way to receive a complete feature list for every program, which is far more than you usually get for GUIs, where you typically end up stumbling through obscure Stackoverflow threads in order to find any kind of help.

→ CLIs are versatile

There is almost nothing that can't be done just using CLIs. They excel at text editing and file management, they are equipped with the most handy tools when it comes to programming, they have music players and browsers and you can even edit pictures if you are brave enough.

→ CLIs allow for automation

The biggest advantage of CLIs is how easily a task can be automated. In everybody's life are tasks that have to be repeated over and over again. It can be astonishing how much time you can waste without realizing it. With CLIs all you have to do is write the needed commands in a file and then execute it. Besides from just that, there are a multitude of other utilities created to automate execution of commands or respective files. For example "Make" is a tool designed primarily to compile programs, but it can also be used to automate testing as well as simulations.

→ Where to start?

Take the next Linux computer or Mac and open a terminal. The first thing to type in is "man intro". This will give you an overview about the absolute basic commands of a shell. It is useful to read the man pages of a few of these commands. You can go further by reading "info coreutils".

Or, if you prefer watching over reading, you can check out the recording of our TheAlternative Linux Toolkit course, which provides an introduction to the Linux command line right here

Happy Hacking!

Jobs available!

We are looking for a working student as Deputy Support Coordinator (50-60%). You can find more details about the position here. Apply now or share the job description with your friends!

Order Information

You can track the order status of your laptop in our distribution partner's customer account. You can find information on this in the FAQ.

Help Point : Please book an appointment

Our support staff at the Help Points ETHZ, Bern vonRoll, UNIBAS and UNILU are there for you. If you need technical support, contact us via email to make an appointment.

Jobs available!

We are looking for a working student as Deputy Support Coordinator (50-60%). You can find more details about the position here. Apply now or share the job description with your friends!

Order Information

You can track the order status of your laptop in our distribution partner's customer account. You can find information on this in the FAQ.

Help Point : Please book an appointment

Our support staff at the Help Points ETHZ, Bern vonRoll, UNIBAS and UNILU are there for you. If you need technical support, contact us via email to make an appointment.

Need Help?