top | item 3358544

The Command Line Crash Course Controlling Your Computer From The Terminal

204 points| goodweeds | 14 years ago |learncodethehardway.org | reply

87 comments

order
[+] jimmyjim|14 years ago|reply
> 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')

[+] dangrossman|14 years ago|reply
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.

[+] Mithrandir|14 years ago|reply
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.

[+] burgerbrain|14 years ago|reply
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.
[+] naner|14 years ago|reply
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.

[+] non123|14 years ago|reply
How to ask questions the smart way?

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

[+] qjz|14 years ago|reply
File and directory names can contain spaces and require special treatment. This should be addressed up front, before introducing commands with side effects.
[+] zedshaw|14 years ago|reply
Oh yeah, thanks I need to put that early in the exercises.
[+] rmc|14 years ago|reply
Exactly. As someone who's taught command line basics, this is a problem that people have a lot at first
[+] jseliger|14 years ago|reply
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,

[+] minikomi|14 years ago|reply
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!
[+] gbog|14 years ago|reply
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.

[+] grannyg00se|14 years ago|reply
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.

[+] morsch|14 years ago|reply
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

[+] robbles|14 years ago|reply
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.

[+] VonLipwig|14 years ago|reply
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.

[+] dredmorbius|14 years ago|reply
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".
[+] zedshaw|14 years ago|reply
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.
[+] jodrellblank|14 years ago|reply
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.

[+] S4M|14 years ago|reply
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.
[+] 8ig8|14 years ago|reply
I know the OP is not the author, Zed Shaw, but I simply wanted to say Thanks to Zed for this.
[+] sc00ter|14 years ago|reply
pushd / popd where have you been all my life?! How did I not know this? Thanks Zed!
[+] dboyd|14 years ago|reply
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.
[+] seany|14 years ago|reply
`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?!)
[+] robert_nsu|14 years ago|reply
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.
[+] jgmmo|14 years ago|reply
I got 1 upvote for anyone that can provide me a pdf of this thing.
[+] zedshaw|14 years ago|reply
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.

[+] Raphael|14 years ago|reply
Why on earth would you want a PDF?
[+] eliben|14 years ago|reply
Zed's productivity is truly inspiring
[+] xradionut|14 years ago|reply
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.

[+] zedshaw|14 years ago|reply
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.
[+] JJMalina|14 years ago|reply
I've been waiting for something like this. Thanks a lot Zed!
[+] jisaacstone|14 years ago|reply
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.

[+] readme|14 years ago|reply
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)

[+] aridiculous|14 years ago|reply
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.
[+] achompas|14 years ago|reply
Was talking about going Linux soon, and this'll help me work from Terminal exclusively. Thanks!
[+] graysnorf|14 years ago|reply
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.

[+] dekz|14 years ago|reply
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!
[+] pault|14 years ago|reply
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.

[+] gcb|14 years ago|reply
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.

[+] Adaptive|14 years ago|reply
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.

[+] AndresNavarro|14 years ago|reply
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