Hacker News new | past | comments | ask | show | jobs | submit login
The Command Line Crash Course Controlling Your Computer From The Terminal (learncodethehardway.org)
204 points by goodweeds on Dec 15, 2011 | hide | past | favorite | 87 comments



> The next warning is stay off IRC or other places where "hackers" hang out. They think it's funny to hand you commands that can destroy your computer. The command rm -rf / is a classic that you must never type. Just avoid them. If you need help, make sure you get it from someone you trust not from random idiots on the internet.

I don't really agree with that. I know for sure that popular channels in OFTC and Freenode are monitored by very smart and responsible people that would never let this happen. In my many years on IRC I have not seen a single novice guy looking for help actually get had by someone intentionally trying to mislead/screw over.

I would instead encourage novices to read this: http://catb.org/~esr/faqs/smart-questions.html#usefora ('How To Ask Questions The Smart Way: Web and IRC forums directed towards newbies often give the quickest response')


My first experience on IRC was looking for help with my first Linux install. Someone in the channel telnet'd into my computer and wiped my hard drive while I was chatting.

I was 9 or 10 years old at the time and my root password was one of those common strings (12345, abcde, I don't remember at this point). It had taken me 3 days to learn how to download Linux, make a stack of installation floppies, find and use partitioning tools, install Linux and set up a boot loader, etc. I cried when I realized what had been done to me.


Unless someone 'fessed up to it, you really have no way of knowing who did this. It could just as easily have been a drive-by script.

And regardless, it was a hard, cheap, early lesson in the importance of ensuring fundamental levels of system security. I've ... suffered worse.

I strongly suspect you'll never forget this.


This being more than a decade and a half ago, I doubt it was a drive-by script. I was dialed into AOL on a 4 letter screen name. I had just informed a channel of Linux users, who knew my public IP, that I had just installed Linux for the first time. The chances it wasn't someone from that IRC channel are near zero.


Yep, it was common to watch new folks join a help channel, and as soon as you saw that root@host identity, the level of shenanigans would jump through the roof.


stop crying


Hah! Downvote it all you want, you know it's true. He needs to stop crying.


I didn't say it wasn't. And given the malicious activity (most scripted attacks, especially today, prefer to make productive use of your system) that's a likely explanation.

But scripted or not, someone did you a favor.

For a reference point, a (very technical) friend at a large tech company had to fire up a fresh Windows VM in order to complete some Windows/IE-only internal web app form.

He was p0wned within 5 minutes. On the corporate LAN. Stats I've seen are that an unpatched WinXP box (pre-SP2) was getting p0wned within 15 seconds, on average by the mid/late oughts. Scripted attacks are that fast and easy.

Scanning an IP range for open telnet ports (n00b move #1) and attempting root logins on same (n00b move #2) with weak passwords (third strike) is pretty trivial. Could have been another AOL user, could have been someone's IRC bot / autoattack.

While not blaming the victim, you discovered (on a freshly installed, no-real-data-present-yet box, hence, very inexpensively) that You Don't Do That[tm].

So: stop crying over this and put on your Big Boy pants. That asshole did you a favor. Really.


> So: stop crying over this and put on your Big Boy pants.

In what world do you think that

1) I'm 'still crying' over something that happened 17 years ago by relating it in a comment

2) It's appropriate to tell other professionals relating a story to 'stop crying'

It's certainly not this one.


Stop victim blaming. This was a cruel and mean thing for someone to do to someone taking thing first steps in learning about hacking.


I'm not blaming the victim.

I am saying that, yes, he did something stupid and got spanked for it.

I'm also saying (and in my highly downvoted follow-up providing additional examples of) that it's reasonably if not highly plausible that the attack was wholly scripted and automated.

I've been burned myself -- by systems stuff as well as meatspace events. Very often the key finding of a particular experiment is "don't do that".

That was my point.


I have seen on some IRCs people writing 'sudo rm -rf /*" etc. (not as advice, but as a joke,) but that person is always promptly kicked out and everyone in the channel tries to warn others.

The author's view is definitely too pessimistic. Most people on IRCs like Freenode aren't evil 'hackers' out to 'hack' you (this reminds me of an episode of Numb3rs.) Other smaller IRC servers can get rowdy, but I've yet to see that on Freenode et al.

I think much better advice would be to not randomly execute crap you see online without knowing what the program is and does, especially in root.


A few days ago I decided to pick up a bash book from O'reilly and, truth be told, the guys in a room in Freenode knew how to help me in any question I made, no matter how silly I might felt for even asking (specifically I remember asking them about case insensitive shell expanding of wildcards which ended up being a locale issue in my installation).

That doesn't mean that they're all saints, I just find it comforting that there are people out there who will gladly assist a complete stranger (in my case, me).


I think the exact opposite advice would actually be more proper. Newbies probably don't often even know about IRC, but it can be a great way to get exposed to some really cool stuff.


The next warning is stay off IRC or other places where "hackers" hang out. They think it's funny to hand you commands that can destroy your computer.

It would be simpler just to tell the student to not run any command unless he or she can explain exactly what the program and arguments mean.


How to ask questions the smart way?

Lesson 1: Register with a female nickname: Jane123, KatyG, ... You'll see response time shorten dramatically.


File and directory names can contain spaces and require special treatment. This should be addressed up front, before introducing commands with side effects.


Oh yeah, thanks I need to put that early in the exercises.


How about including some examples of globbing all files of a given type including filenames with spaces?

e.g. 1) Find all file names in a directory that contain spaces and replace spaces with _

2) E.G save mp3 format sound out of a directory full of flv files using ffmpeg, flv files can have arbitrary file names, mp3 file names saved with no spaces

That kind of activity would be interesting to younger proto-hackers

I'm a teacher. A group of teenagers in a computer room (which is not your target audience) would not actually read your tutorial in an a to b fashion, but, when set a task would raid your work for the bits that help then achieve the task. I'd then follow up with a multi-choice quiz in Moodle or something similar to structure recall like your flashcards.


Exactly. As someone who's taught command line basics, this is a problem that people have a lot at first


I just wrote to Zed:

I haven't read past section 0 yet, but I do have a suggestion for people who want to learn how to memorize things faster: use SuperMemo or a modern equivalent, like http://ankisrs.net/ . Such programs use spaced repetition techniques to improve memory speed. I used Anki for improving my French and recommend it. If you'd like to learn more, see http://www.wired.com/medtech/health/magazine/16-05/ff_woznia... .

Cheers,


Anki and Mnemosyne (http://www.mnemosyne-proj.org/) are both available from the Ubuntu repos.


I was recently given a small netbook and took the plunge with arch / xmonad and it has been pretty eye opening.. Going from "I need more control over screen brightness", to being able to assign keys that control the display precisely how I want has been frustrating and satisfying in just the right way. Thanks Zed for another great source!


On page 3, about "whoami"

> type this command 20 times and say it out loud

I have many years of daily command line use behind me and never needed to use this command. I don't like being taken for a child.


I agree. The tone is not for me and it sounds really put on.

"The only piece of advice I am going to give you is this:

Shut the hell up and type this in then try to understand it.

Sorry to be mean, but that's what you have to do. You have an irrational fear of the command line and the only way to conquer an irrational fear is to just shut up and fight through it."

Why say "shut the hell up"? Why assume that the reader has an irrational fear? Most people are just trying to learn because they currently don't know. Not because they are afraid. They don't need some kind of drill sergeant to aggressively push them into it. They've already taken the initiative to seek out the knowledge and begin reading it.


Is it the word "hell" you disagree with or being told to do something? If it's "hell" I can remove that. If it's just because you don't want to be told to do something then don't read my book. You won't learn anything from it since the entire book is me telling you to do repetitive boring tasks.

As for why I wrote it: You may not have an irrational fear but a huge number of Windows and OSX users do. They've been told that the CLI is dangerous and antiquated so they avoid it and panic over it. Having someone like me just push them through actually gets them past that and on to learning how to use it.


First off, thanks for writing something like this in the first place. I do believe that overall it is a helpful addition to the vast collection of instructional material that is available online.

Regarding the tone of the text, it's not the word hell specifically - it's the overall tone, which is echoed elsewhere. You could've said "Shut your yap..." and that would have been just as bad. Why are you browbeating or scolding your readers as though they are misbehaved children? Telling someone to shut it is condescending, dismissive, offensive, and simply rude.

It's like you're trying to help me, but you've been pushed into it and are now pissed off. And god damnit we're going to get through this one way or the other and if you have to beat me into submission and force my hand then that's what you'll do.

It's just a personal opinion. I find it makes the experience less pleasant with that kind of writing.


I agree. I don't mind tongue-in-cheek rudeness or expletives in how-tos in documentions, but this thing just struck me as unpleasant and hostile. I'm not sure the format is well suited to the goal, either, and some of the didactic methods seem bizarre.

I'm sure better tutorials have been available for years. E.g. http://linuxcommand.org/learning_the_shell.php


Then why work through the examples?

The "learn by rote" method he's using here is designed to help people with little or no experience catch up quickly, and remember what they've learned without the many years of daily use.

If you just want to learn the odd helpful new trick, and basically know what you're doing, just ignore these parts.


That is just one example of the tone of this book, and I just don't like it, and I don't understand why it has so many supposedly adult people accepting things like:

> No, seriously, type it 20 times and say it out loud. Sssh. Just do it.

I supposed it was a kind of cold joke but it appears not to be. It is just very disrespectful for the reader. Grown up human beings are not to be taken by the hand like /this/ to learn something as serious and advanced as command line.


And here you are complaining, avoiding, being offended, giving your opinion, generally doing anything and everything except learning.

Seriously. Shh. Just do it. Shh meaning stop all the opinionating. Just do it meaning only do that and not all the surrounding fuss and bluster.

It's not disrespectful, it's pragmatic, you're reading his book to learn, what are you doing thinking things like "I don't want to type it 20 times, I've typed it 5 times and I know it already, this is stupid, it's boring, I'm not saying it out loud, that's embarassing, blah blah blah"? You chose to read this book to learn, do what he says. No, shh, just do it.


Grown adults are taught in a manner similar this everyday in basic training for the army. They teach far more serious topics, and it's effective.

Also, smart people learn to skim and skip when needed. Writing like thus serves both cause the smarter ones skip.


The problem is not with rote learning. The problem is with the tone of this. Compare with LPythonTHW for an example of similar rote learning, but with explanations of why and a less angry tone.


You can't seriously compare teaching command line kungfu to some wannabee geeks in their spare time with the hardcore brainwashing given to infantry troops so they acquire enough Pavlovian reflex to stand and run below a shower of bombs and bullets.


There are jobs like EMT or piloting aircraft where rote knowledge and practiced skills are necessary to save lives. The methods are effective in many tasks and careers. Touch typing is a good example. How long did it take you to learn to type your odourous knee-jerk reaction?


Your characterization of both is wrong.


Pray explain a bit in which ways my characterization of both is wrong.

(As any short description, my "portrait" maybe a bit of a caricature but I believe it expresses the meaning well enough.)


"You can't seriously compare teaching command line kungfu to some wannabee geeks in their spare time with the hardcore brainwashing given to infantry troops so they acquire enough Pavlovian reflex to stand and run below a shower of bombs and bullets."

1. All geeks learned the command line at some point. Even Linus. Calling the next Linux a "wannabee geek" is wrong.

2. basic training is for all soldiers, not just infantry soldiers. You choose infantry for the baggage it carried, and you didn't care that you were flat wrong.

3. I find your use of "pavlovian reflex" wrong. It has a negative connotation, but is all reflexive action "pavlovian". If so, all of my command line use is pavlovian because I do it reflexively without conscious thought. With that in mind, the military style is perfect because it's designed to train people to do things reflexively when the time comes.

4. basic training teaches many great things. You're dismissal of it as teaching people to "run below a shower of bombs" is wrong. I learned CPR amongst many other good things in basic. Things that again require one to do them almost reflexively, just like I use the command line.

In short, you are wrong.


1. If Linus is a geek (he is, isn't he?), then the next Linus is a wannabee geek. How is calling a wannabee geek a wannabe geek somehow wrong?

2. It was an example and he never said basic training was ONLY for infantry.

3. You say all reflexive action is pavlovian but then say that using the term pavlovian reflex is wrong. That is wrong.

4. He never indicated that basic training doesn't teach some decent things. However, it does also teach people to act on orders without thought. You may not like the reality communicated, but the reality is that one of the objectives for basic training is to indoctrinate and enforce conformity. So that when you do have to run below a shower of bombs and bullets you don't question it, you just do it.

In short, nothing he wrote was wrong. You just didn't like it.


I'll simply say that using the command line is a reflexive act, and that basic training, which is good at teaching reflexive actions, is a good model to use.

He thought otherwise, and since this the core of the issue, I believe he is wrong on the primary point.

His wording was intended to imply negative things with loose language, and if you can't see that then you can't.

I'll give one example. I said, "Grown adults are taught in a manner similar this everyday in basic training for the army."

He said, "You can't seriously compare teaching command line kungfu to some wannabee geeks in their spare time with the hardcore brainwashing given to infantry troops so they acquire enough Pavlovian reflex to stand and run below a shower of bombs and bullets."

You claim he didn't say that basic is ONLY for infantry. True, but then I have no idea what he was saying. I said that basic is a good model for teaching reflexive action. He was responding to that, so he was either creating a straw man with the infantry thing, or he did get it wrong that basic is ONLY for infantry.

Right?


also, a wannabe is pejorative, here's the wikipedia definition.

A wannabe (slang for "want to be") is a person with an ambition to be someone or something that she/he is not. The term is pejorative and intends to convey the foolish nature of the desire due to the incompetence of the "wannabe" to accomplish the goal.


If you don't like it use something else.

Copy and pasting usually means you never knew what the code said anyway.

Typing it once means you will remember it till the end of the day but tomorrow? The day after?

Typing it 20 times and saying it out loud to yourself helps it stick. There is no need to run to Google to look up the command. You should know it after doing it this many times. Especially if in the following days you recap with some basic memory exercises.

I have always thought that this is what set's Zed Shaw's books apart. They teach you a language in a way that sticks.

If you don't find it useful or for your style of learning pick up a book focusing more on theory rather than doing.


It's handy in a multi-user environment when you're sudo/su -ing to various users. I'll use it reasonably frequently to test that sudo works as anticipated. "sudo whoami" should return "root".


Yup. "id" is pretty good for that too, and is shorter to type. Give it a whirl.


It's not meant to be insulting, it's meant to be a method of learning the basics of a language that works. If you're insulted by it then just don't read it.


Your goal: A resource containing a method for learning, in a non-insulting way, for people to use.

What happened: People reporting of being insulted.

So you failed, why not use the feedback to improve the thing instead of making it personal.


When somebody says that they didn't mean to be insulting, that doesn't mean that they meant to be non-insulting. If I run to catch a bus, and I didn't mean to start with my right foot, it doesn't mean that I meant to start with my left.


> in a non-insulting way

I don't think that's part of the goal.


I don't like being taken for a child.

That's a problem with you which you should fix, instead of getting all defensive and whiny.


I tried to express a view differing from the global appraisal in the comments. If it sounds defensive and whiny, maybe it is a problem with the way I expressed it, but it was not meant to be.

I don't like "for the dummies" books either, I think this relatively new way to write books teaching something is no good for anyone. Showing a supposedly humorous disrespect for the reader seems to be acceptable in some cultures. It is not in mine. A very strong bullshitting of the reader is ok in some literary works, as it is part of the facture of the book (I am thinking LF Celine), but it is not ok in utilitarian literature.

But, you'd tell me, it is a first-world problem, I can live with this new trend (it will be replaced soon enough), as long as I am allowed to express out-fashioned point of views in places like HN.


Not liking something is different than it being "no good for everyone."

Though you see that your culture is not everyone's, not acceptable within your culture is not equivalent to not acceptable full stop.

Not everyone agrees with your permissions rule distinctions between instructional works and literary works, but this does not mean that what they are doing is not ok.

Being criticized is not the same as not being allowed to express yourself.

P.S.: Characterizing all possible arguments against your position as soon to be replaced trendiness disqualifies anyone from having a discussion on this subject with you, and pre-insults anyone who would want to.


Ok, you have gained some rethorical points here. Some of my comments were a bit defensive, as a result of a feeling that I was circled. In fact some other commenters expressed views similar to mine and my first irruption has had some upvotes. Obviously some people understood what I meant, so I am not sure if it is needed to continue to explain.

Just a note: When I said "Showing disrespect for the reader seems to be acceptable in some cultures. It is not in mine.", it was just a polite way to say. (To say what? I just wrote it, but after some thought I yanked the thing. It was talking about culture as universal need for cultivation of oneself, aka education, aka civilization.)


Well, as someone who has "many years of daily command line use" behind him, you will not learn anything from that book targeting newbies, but if you try something you're a complete noob at - a foreign language sticks to my mind - you will have to use this kind of technique to memorize the things you will learn.


I know the OP is not the author, Zed Shaw, but I simply wanted to say Thanks to Zed for this.


You're welcome.


pushd / popd where have you been all my life?! How did I not know this? Thanks Zed!


Related to that... the 'cd' section seems to be missing "cd -" (ATM).

    $ cd /some/really/long/dir
    $ pwd
    /some/really/long/dir
    $ cd ~
    $ pwd
    ~
    $ cd -
    $ pwd
    /some/really/long/dir
I'm pretty sure "cd" and "cd -" are my most used commands. CDPATH ranks pretty important too.


What is the difference between the three?


~ is your home directory. - is the last directory you ran cd from. For CDPATH see this http://www.caliban.org/bash/#bashtips



`please` don't use this in scripts. It makes it so hard to debug things later when the next guy comes along and has no idea where you end up after you pop. (can you tell this has been happening to me recently?!)


I've been watching this for a little while. With powershell, a lot of the *nix commands have been or can be aliased to the windows commands (e.g. ls and Get-ChildItem). Judging from his notes so far, he isn't taking advantage of this, but hopefully he will.


I got 1 upvote for anyone that can provide me a pdf of this thing.


http://dl.dropbox.com/u/8605032/cli-crash-course.pdf

git clone git://gitorious.org/the-cli-crash-course/the-cli-crash-course.git

Use dexy with a Tex install and it's a cinch. Only hiccup might be a few specialized Tex packages it complains about needing.


I was very psyched to see this, however, I am afraid to tell you that this is missing parts of the text. It is missing the 'Do This/Source Examples' - a vital part of the text for sure. Replace with fixed copy and report back! Thank you kind sir!


Updated to the latest version of dexy and all appears to be well. The link should now have a working copy.


Very good, thank you!


Hmmm. So it is. Not sure why just yet. I'll give it a shot debugging the Tex. Maybe something in my setup.


Feel free to read the PDF, and I'll be putting it up for free since it's a huge benefit to my students if they know the CLI.

But, PLEASE, do not pass the PDF around to newbies until I say it's ready. Having old versions with potential errors floating around or that are half-done is really bad for them.


Why on earth would you want a PDF?


Zed's productivity is truly inspiring


Am I just a cranky old geek or does anyone else find Zed teaching CLI skills mildly amusing? Or is there truly a large population mentally bound by the graphical interface?

Know the basic commands of getting things done isn't just for the experienced admins/developers like myself who have been using keyboards and terminals since the early DOS and VMS days. Ordinary users were able to create documents, check mail and write simple Excel macros, etc. Coworkers shared tips, people had books and kept notes. None of this has ever been rocket science.


Yes, sadly Microsoft (and to a certain extent Apple) have done an excellent job convincing people that the CLI is both dangerous and antiquated. So when they come to my other books and I tell them to use the CLI they have major problems. I'm writing this mostly as a quick way to get them over that speed bump then on to more useful programming topics.


I've been waiting for something like this. Thanks a lot Zed!


Once again - another resource with almost no windows support. At least he has a todo. . .

Back when I just did PHP and never used a command line having a widows box was painless. Recently I have been learning UNIX at work and Python at home and have been impressed by the lack of resources/support for working with Windows.

I suppose I should stop complaining and just blog what I've learned so far . . . though admittedly it isn't much.


No problem, just install mingw. Or install msysgit and you get git-bash which comes with it. CMD.exe is a pile of garbage. I would understand if you wanted to learn about powershell, though. That's definitely on my todo list.

Also, CMD.exe has copy + paste, you know? You can right click to start a mark, then left click and drag. Enter performs the copy. However, it doesn't understand newlines or line wrapping, so you end up getting artificial newlines where the end of the terminal is (which is unfortunately capped at 80 chars, so if you wanted to make it bigger, you couldn't)


I like the tone of the books. It makes things interesting and you feel like stuff is getting done. Just wanted to throw that out there since most of the comments are complaining about it. I don't want you, Zed, to get the perception that everyone is sheepish about it.


Was talking about going Linux soon, and this'll help me work from Terminal exclusively. Thanks!


I second dekz's encouragement. I went from windows/eclipse to windows/eclipse + cygwin to linux/eclipse to linux/vim(et. al).

It's worth it. It really is. At some point you will marvel that you ever thought it was a good idea to navigate filesystems with the mouse, or edit text in a non-modal editor.


You won't regret it! I'm not sure if I could ever stand windows as a main development environment again. POSIX is just a lovely environment to be in. Once you get the hang of it you'll see you become a lot more faster at mundane tasks (even scripting them). Good Luck!


I use a macbook as my main workstation, but all my development happens in linux VMs. It only takes a few minutes to install a headless ubuntu in VMWare, so I create a new one for every project I start. This has several advantages:

- No configurations/installs from previous projects screwing things up (I know you can use tools like RVM and virtual-env, but in my experience starting from scratch is easier).

- Snapshots. It's great to be able to restore from a snapshot when you bork an upgrade.

- I've become very good at configuring a basic LAMP stack from memory.

Screen+Vim and the ability to suspend/resume machine images makes for an extremely flexible and ubiquitous development environment. I've considered doing this with AWS but there are still odd times where I find myself without an internet connection.


Hey - I like doing this but find the power consumption of my laptop goes through the roof, and it gets uncomfortably warm. Does anyone have any tricks for beating this? I've just upgraded to latest vmware but haven't deliberately tested this yet.


always considered myself an ace of the command line... heck for some time i even used X only for webbrowser (while cursing) and used TTY1 for vim and TTY2 for a shell where i'd run version control commands and build...

but yesterday, installing debian-testing on a new notebook, the radeon cards didn't worked out even with the vesa drivers and i had to use the console for a few hours...

i panicked when i realized I had no idea how to bring the wifi up.

...and everytime something like this happens (previous one was some punk changing the kernel parameter "single" or "1" or "init 1" to "text")... i feel old and outdated. it hurts.


I find wifi on the command is still surprisingly hard if using just primitives like iproute2. I'm trying to force myself to use just that for a bit to learn the new(ish) ip / iw commands.

Really, though, wpa_supplicant seems to be the most troublesome critical wireless "primitive". Not fun command line syntax.


I've had successful experiences with ceni--a relatively unknown interactive network manager. http://ubuntuforums.org/showthread.php?t=918442


I found about this problem when moving from gnome to a minimalistic window manager that had no task bar whatsoever. I now use cnetworkmanager which is a python cmd application that uses dbus to connect with the regular NetworkManager service in Ubuntu, but for a couple of minutes it was a weird feeling, not being able to do something this basic


You might consider switching to a lightweight distribution like Arch. Distributions intended to be used from the command line give you tools to make these tasks easier.

https://wiki.archlinux.org/index.php/Wifi




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: