3

This may be a rather simple question but here goes.

I am thinking of learning to use a CLI as I have been told it is more efficient for a technician to use than a GUI. Could someone please outline why it would be benificial to use a CLI?

closed as primarily opinion-based by jasonwryan, Stephen Kitt, Networker, mdpc, slm Apr 30 '15 at 21:16

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Not only more efficient, but it really is quicker to get things done just using the command line.... – ryekayo Apr 30 '15 at 19:59
  • 1
    With a caveat - if you know what you're doing, CLI is better. The singular advantage of GUIs is that you can 'fiddle around' to do something. For example - on Windows, launching the 'control panel' and flicking through stuff you might want to adjust. I'd suggest that's still probably easier because you're not doing it frequently enough to 'just know'. – Sobrique Apr 30 '15 at 20:14
  • @Sobrique: The main advantage of GUI is that it gives you an algorithm ("click on all menus, click on all buttons") to discover / be reminded what you can do. Translating that into useful fiddling still depends on you having some idea what you're doing. It certainly helps to have menus and buttons grouped by logical functions. But if you have no idea about, say, graphic editing, you won't be able to do anything useful with Photoshop, despite it being 100% GUI. The other main advantage of GUI, interactivity, really shines when you're already comfortable with using the interface. IMO. – lcd047 May 1 '15 at 19:39
9

It's all about metaphors for communication. GUIs are picture books - they let you move things to other things, or right click on things and select options.

But you still type a post when you want to ask a question.

Command lines are much the same thing - they're about telling a computer what to do. If what you're trying to do is simple, then pictures and words are about the same. If what you're trying to do is complex, then words allow you to explain better.

One of my favourite examples is find.

find . -mtime -60 -name '*.txt' -exec sed -i.bak 's/fish/carrot/g' {} \;

This will:

  • Search the current directory structure
  • for all files modified within the last 60 days,
  • called '*.txt'
  • replace the word 'fish' with 'carrot' in all of them.
  • leaving a backup copy suffixed .bak.

How would you illustrate that pictorially using a GUI?

(And to extend it - the next phase of the command line is to learn scripting, which lets you explain in more detail what you want the computer to do).

This principle goes double for long running and time consuming tasks. You write your command to do it, press 'enter' and save the output. - go home and leave it going. Where complex GUI commands you have to run one at a time.

The core advantage of GUIs in my mind is that they do let you have a range of things to do without needing to know specifically. Control Panel in Windows is the place you look when you want to 'fiddle with some settings' - and you can flick through them looking for something appropriate. I would suggest for infrequent tasks, that's beneficial. It's probably still (in my opinion) easier to do that with Windows than it would be on Linux.

But that's really the same point - for infrequent tasks performed occasionally, GUIs are good. For complex and regular repeatable commands, CLI every time.

  • That answer has helped me understand no end! Thanks! – Swifty124 Apr 30 '15 at 20:11
2

The single most important advantage of CLI over GUI is that with a CLI you can easily connect a command's output to another command's input. This connection has a simple and intuitive notation (a pipe, |), and its implementation is highly efficient. This allows one to solve complex tasks by chaining together very simple building blocks.

For example, this piece of code removes duplicates from a collection of images:

find ~/Images -type f -name '*.jpg' -print0 \
    xargs -0 shasum -a256 | \
    perl -l0ne 'm/^(\S+)\s.(.+)$/o and $a{$1} ? (print $2) : ($a{$1} = 1)' | \
    xargs -0 rm -f

Each of the commands involved does a very simple thing. Each command is easy to understand, and the correctness of its functioning is easy to verify. Yet the result of chaining these commands together is far from trivial. With a GUI one doesn't have this level of modularity, or flexibility.

Not the answer you're looking for? Browse other questions tagged or ask your own question.