News for hackers. Stuff that matters.
Re:Learn the Command Line by izolate on Monday August 24, 2015 @05:39PM (#10113070)
Lately I've been butting heads with some seriously anti-command line people. I'm not sure if this is a growing sentiment, or I'm just advocating CLI usage more as time goes on.

Anyway, glad to see this. I'll be sure to recommend it to whomever I'm preaching.

Re:Learn the Command Line by Nadya on Monday August 24, 2015 @06:01PM (#10113156)
I can often navigate to a file in a GUI faster than I can "cd users/Nadya/documents/work/2015/08/24/important/file.txt" [0]

Or I could open up my GUI, click "work" from my side nav selections and navigate through 2015/08/24/important/ and click my file to open it. I can even open two directories and ^x^v into another directory. Or drag/drop to move. Rather than "mv file.txt ../../25/file.txt"

I think it's important to show the more "cool" stuff you can do from CLI. Once you have them interested, explain the building blocks for how they can get there.

Explaining the building blocks to someone who doesn't see the benefits of the CLI will have them thinking about trivial problems and wonder why anyone would ever choose to use the CLI when the GUI is so much faster/easier/less memorization. When I was taught pwd/ls/cp/mv all I could ask myself is "....why? GUI is faster/easier/less memorization/no typos wasting time".

[0] To be fair, I can autocomplete a lot of that command. GUI is still faster though. "cd/us[tab]/N[tab]/doc[tab]/wo[tab]/2015/08/24/i[tab]/fi[tab].txt"

Re:Learn the Command Line by a3n on Monday August 24, 2015 @09:32PM (#10113937)
I don't think speed is the best argument pro the command line. If you're used to and proficient in a gui or cli, then it's going to feel like you're getting more done in your familiar environment.

To me the killer argument for cli is composability, combined with the cli history.

Most of us do a lot of things repeatedly, day in day out. For example I have to download one of the last files from an ftp server, open it, process it in some way, and possibly get some other files based on what's in the first file.

It's reasonable enough from the command line. But some of the operations are chainable with pipes, and all of them can be in a short shell script, so I only have to enter the one script name to get the whole thing done.

And it's in my cli history, so I only have to recall it, and change usually just one parameter.

I think I'd be hard pressed to do that from a gui. for one, I don't think there's a gui history. And how do you chain gui commands together? And then alter them with parameters?

"Write a $LANGUAGE script that you can double click on." Yes, but that's a higher barrier to entry, and it's in a completely different "language" than the gui language that you were working in when you discovered a series of tasks that you repeat. With a shell script you just pull together what you've already been doing, in the format that you've been doing it.

And then compose the shell script you wrote with other shell scripts that you wrote. Etc.

I double click on things too, and somethings it's merely a matter of whether I have my hand on the mouse or the keyboard. Not bashing gui's (pun intended).

Composability.

Composability.

Re:Learn the Command Line by wingerlang on Tuesday August 25, 2015 @01:20AM (#10114730)
> I think I'd be hard pressed to do that from a gui. for one, I don't think there's a gui history. And how do you chain gui commands together? And then alter them with parameters?

Some automation tool like (osx) Keyboard Maestro is pretty good for these kinds of things. Just started playing with it the last couple of weeks but it is very powerful.

I use CLI automation as well quite a lot.

Re:Learn the Command Line by na85 on Monday August 24, 2015 @06:10PM (#10113190)
Your GUI often includes shortcuts (e.g. to your "work" folder) and that functionality is accessed from the command line via symlinks. Your comparison is not really fair.

It's significantly faster (at least for me and most people I know) to type "cd ~/relevant-symlink" than it is to take my hands off the keyboard, switch to the mouse, and then go back to home row.

Re:Learn the Command Line by phaemon on Monday August 24, 2015 @06:13PM (#10113199)
You can't 'cd' to a file :-)

Seriously, if you have 'work' as a side nav, then you could have it as a symlink, which makes it about the same. But it's really the stuff like looping over operations, or rsync over ssh, etc that make reading & writing a bit more awesome than point & grunt.

Re:Learn the Command Line by Nadya on Monday August 24, 2015 @06:50PM (#10113365)
Arrgh, you caught me! ;) Replace cd with nano and I'll try to avoid the text editing via GUI vs text editing via CLI debate.

As for symlinks, it's a fair point. But even typing the rest of that example it would be faster for me to use a GUI.

I agree on that point. CLI is much better for less trivial tasks - or making a trivial task possible. On Windows renaming files is bad, ending with an (n) structure. Where I want "file_1.txt, file_2.txt I get file (1).txt, file (2).txt. Or if I save a bunch of .jpf instead of .jpg I have to use the CLI to fix the extensions because it isn't possible in Windows otherwise.

But you won't convince a lot of people to use CLI if you're introducing them to pwd/ls/mv/cp instead of |'s, grep, scripting, etc.

Re:Learn the Command Line by deathanatos on Monday August 24, 2015 @06:56PM (#10113377)
> You can't 'cd' to a file :-)

I'm routinely tempted to alias `cd` to something that will open the file in $EDITOR, if I type `cd <a path to a file>`.

Re:Learn the Command Line by earthboundkid on Tuesday August 25, 2015 @08:32AM (#10115956)
CLI is better for when you know where you want to go, but it sucks for exploration. It takes much more effort to learn how a file tree is laid out using the CLI than it does using a GUI.

It's much simpler to move your mouse and click once than to use cd + ls. (Never-mind the fact that half the time I go to use ll and oops, this is a super-user so none of my aliases work.)

OTOH, if you're always moving files from /stage to /live or /db to /backup, CLI is more efficient, particularly once you write a script to capture what you need to do.

GUI also comes out on top for anything where the CLI ends up just being a mock-GUI. For example, on OS X, there's no reason to use top instead of Activity Monitor, since they do the same thing, and AM lets you click the column headers to re-order things. Also, I know people love vim/emacs, but those are both better as GUIs than as pure-terminal programs.

Re:Learn the Command Line by nekkoru on Tuesday August 25, 2015 @10:41AM (#10116817)
Why not create a series of (edit: autoupdating) symlinks like ~/today and ~/yesterday? Just a thought.
Re:Learn the Command Line by rconti on Monday August 24, 2015 @07:44PM (#10113514)
I'm actually shocked to see such a massive number of coders on HN (a skill that still somewhat eludes me) can't use the command line, which I consider a Step #0 type prerequisite.

It just hadn't even occurred to me that this might be a possibility. I'm not even sure how folks get started in the hobby/skill without the CLI background.

I'd be interested in hearing more about the skills progression of these folks, and how they got to the expertise they have today.

Re:Learn the Command Line by tperson on Monday August 24, 2015 @11:01PM (#10114345)
I started programming in PHP doing web development. I started on Windows ME/XP and primarily used FTP to a free PHP host. After a while I learned to setup PHP/Apache/MySQL on my desktop and continue withing just an editor. Never once really touched the Window cmd.exe. After playing with PHP for a long time I started learning about different frameworks. The one I picked up and used the CodeIgniter. The first time I really heard about using a CLI was when I was reading about frameworks and came across Zend. It was annoying to me that I needed to use some "weird" command line to generate files. Why couldn't I just make them in my editor?

It wasn't until I installed linux that I really started to play with any CLI. I honestly don't remember what got me into linux at the moment. I do remember one of the first things I did was learn to setup the system using a tutorial on howtoforge.com. I went through those tutorial many of times setting up my computer.

I was an avid gamer at the time, so I also had my desktop setup to dual boot Windows. After a while I got tired of switching between the two so I ended up taking an old Dell Optiplex 110 installing CentOS on it and trying to get Samba to work so I could mount my web directories on my Windows machine and still edit them, while having Apache serve them.

I did that for a while, then got a job and bought hosting with shell access.

Re:Learn the Command Line by marssaxman on Monday August 24, 2015 @07:58PM (#10113567)
The classic Mac OS did not even have a command line interface, so people who began their programming careers in the Apple world between 1984 and 2001-2002 would only have had reason to learn how to use one out of curiosity, or if they happened to be doing cross-platform work with a Unix system. I had a wee bit of Apple II experience prior to the Macintosh, and I suppose you could call the various BBS interfaces I used a form of "command line", but for the most part I never touched a command line as we know it today until the late '90s when I started messing around with Linux and with shell accounts on the Internet.

While I've never been part of the Windows world myself, it has always seemed to me that the DOS command line plays a much smaller role there than the shell does in the Unix world. From '97 or so onward it has always been possible to buy a copy of Visual Studio and use it to build software without ever touching a command line, and I'm sure a great many people have done so.

Re:Learn the Command Line by cbd1984 on Monday August 24, 2015 @10:25PM (#10114174)
> While I've never been part of the Windows world myself, it has always seemed to me that the DOS command line plays a much smaller role there than the shell does in the Unix world.

Indeed. It was possible to meaningfully use the command line up through, say, Windows 98 SE or so, once Windows XP hit, it became a relic, stuck in the command.com era while the actual OS kernel moved away from the DOS-hybrid of the Windows 95 era with the shift to Windows NT-derived OSes.

Power Shell (or however that's branded... CamelCase? Alloneword? Hyphenated?) promises to make the Windows command line relevant again, but I honestly don't know if you can meaningfully use a Windows system from only the command line these days. You probably can't use a desktop Windows system that way, which means the command line is still effectively frozen out from the real world.

Re:Learn the Command Line by ccallebs on Tuesday August 25, 2015 @10:52AM (#10116904)
PowerShell is a really cool, powerful tool. Though, it's really more of what you'd consider a modern REPL to be than a conventional shell. It takes an OO approach to scripting as well.

For some reason, I seems like it's a hard sell for a lot of .NET developers. A substantial number never leave Visual Studio and old habits are hard to break. I left that ecosystem many years ago, but still try to keep up with it.

Re:Learn the Command Line by dcposch on Monday August 24, 2015 @10:42PM (#10114250)
I use the shell every day, and I have mixed feelings.

1. The core concepts are beautiful.

Pipes are elegant. Simple programs that read and write text are one of the most enduring abstractions we've come up with.

I've used a single, surprisingly readable command that:

- dumps a database with mysqldump - zips it - sends it over to another server - unzips it - loads it into mysql

...in a single streaming operation, without creating any files! Making a lot of disparate programs, written decades apart, work together so seamlessly is simply impossible any other way. The shell is powerful.

2. The implementation is unnecessarily complex and fragmented

The standard commands all have cryptic names like `ls`, `cat`, and so on. They're second nature to us, but we've made the barrier unnecessarily high for new people who are just learning. Man pages suck (bro pages are much nicer). There are a lot of shells (bash, sh, zsh, etc). They're similar but subtly different. Standard commands like `ps` are incompatible between OSX and Linux, or even different flavors of Linux. Simple operations often require cryptic incantations. I type `tar -xzvf` at least once a week. The original Unix ideal is minimalist and beautiful, but the rest of the experience feels like it was crafted by neckbeards without regard for usability or learn-ability.

3. Shell scripts are terrible

A fresh, out of the box Ubuntu installation contains (very roughly) 100k lines of shell script, probably more.

For writing actual programs, `bash` is one of the worst programming languages that exist.

It makes languages like Perl or PHP look sane and principled.

Every time I use a solidly engineered system (say `buck` for building a large Java project) next to an equivalent shell-script-based system (say autogen + configure + make for a typical C++ project), I'm blown away at how much faster, cleaner, and more robust our software could be, and I feel sad that we've built so much on top of Rube Goldberg shell script contraptions.

---

I think there's room for a ground-up Unix, true to original principles. I would love to make a minimalist Linux distro that boots without executing a single line of shell script. Configuration would be via a small set of JSON files, not some Turing-complete hairball language. It would still have a shell, but it would be a minimal, sane shell. You'd be able to type `help` for a complete and concise listing of available commands, each with a one-line example.

Re:Learn the Command Line by a3n on Monday August 24, 2015 @09:11PM (#10113843)
I don't advocate anymore, unless there's some slight interest to begin with. I'm that weird old guy whose terminal is always running.