Live data from Hacker News

Ask HN: how did you learn the command line?

news.ycombinator.com

41–50 of 59 posts

Re: Ask HN: how did you learn the command line?

#41
Like others here, I learned simply by doing and fumbling my way around until I was comfortable.

That said, I think the most important thing for you to learn is how to get help. Learn how to find man(ual) pages, and how to interpret the very precise language and syntax that programmer-authors like to use. Then try reading the man pages of the systems that you want to learn - like 'man bash'. Also, some tools have nicer pages accessible via the 'info' command, so try 'info emacs'.

That'll generally be the best way to learn how to use any tool. The only trick past that is to learn which tools exist, and google/stackoverflow will usually suggest appropriate tools when you tell it precisely which problem you want to solve.

Re: Ask HN: how did you learn the command line?

#42
I learned Unix on my dad's Tandy Model 16 machine -- one of the first commercially available Unix micros (along with the Sun Workstation).

XENIX (Microsoft's Unix) came with a program called "learn" which was a tutorial. It would show you how to do something, then give you a goal and drop you into a mock shell. Most of the commands had their usual effects inside the mock shell, but you could always quit the lesson and restart if you screwed up.

That's how I picked up the basics. When I discovered Unix machines -- and Linux -- on my university campus some eleven years later, all the old skills translated and I learned some new ones along the way.

Re: Ask HN: how did you learn the command line?

#43
I think that in order to learn the command line, you have to immediately develop a different goal that requires proficient use of the command line. That way it'll force you to learn by doing.

Command line is not one of those self-contained "deep" knowledge bases where everything links together. It's broad, shallow, unlinked - the concepts and practices do not always imply themselves. For bodies of knowledge that fit that pattern, you have to learn by doing - you can't simply derive the knowledge through study and thought. And the best way to learn by doing is to immediately apply it to something useful.

Re: Ask HN: how did you learn the command line?

#44
How did _I_ learn the command line?

By doing. Some reading, sure, but .. more doing than thinking. Like this;

I was a brand-new programmer (COBOL). The Marines assigned me to a billet in the LAN team at my new command. A corporal wrote down exactly what to type on the computer after the NIC was installed.

After that, I was off and running.

Re: Ask HN: how did you learn the command line?

#46
post #29

Everyone's assuming the poster means Linux, but he didn't actually specify. Lots of things have command line interfaces. What command line are you actually talking about?

Much of this advice is applicable to any Unix. For instance 'man man' is good advice on a Mac, too.

Re: Ask HN: how did you learn the command line?

#47
must have been 1999/2000. My boss made me, the ultimate noob, the "administrator" of a Solaris Box.

I didn't know SHIT! absolutely NOTHING. I was just a dumb Windows User. There was just this blinking cursor (that motherfucker) and me. i browsed the web and had to look up stuff like "cd" and "ls". Steep learning curve, i guess, but nothing teaches you better than "trial and error".

Funny sidenote: Not only was i totally overwhelmed with all the commands and quirks of the command line, but the web always mentioned vim as THE editor for Unix. So i also started messing around with the most obscure editor on this planet.

These were rough times for me, but i have learned so much, and i am thankful for that.

Re: Ask HN: how did you learn the command line?

#48
post #17

The best way to learn is by doing and using it often. Don't read, use it often! There must be a strong reason to learn, and don't just learn for the sake of learning! I have been using Linux daily, its around 5+ yrs. I play around with numerous VPS remote boxes and still I'm learning, but everyday getting better at it. This way, it should only get better and better over time! The more you use in your daily workflows,…

[deleted]

Re: Ask HN: how did you learn the command line?

#49

I came to answer your question and say that when I started computing there was only the command line - there were no windows, effectively no graphics, and the only thing you could do was type commands. But then you ask if there are tutorials, and that I can't help you with. Having said that, I tried this search: http://www.google.co.uk/search?q=command+line+tutorial and I got lots of hits, including these: * http://w…

Me too, that's all there was. And that may be the answer: only allow yourself the command line for longer and longer periods of time. Force yourself to learn it.

I really like this book, even today: http://shop.oreilly.com/product/9780596003302.do

The key to being proficient at the command line (as distinct from writing shell scripts) is to think of it as composition.

For example, run this:

  $ file $(which $(man -k python | cut --delimiter " " --fields 1))
(The first '$' is your command line prompt, yours may differ; you don't type that. The other '$' characters you do type.)

Now run each command from the inside out, starting with the man command. See what each command does. Build it up bit by bit, that's exactly what I did, like this:

- the man command

- the man command piped into the cut command

- the man command piped into the cut command after reading "man cut" to remember about the --delimiter option

- the output of that pipeline fed to which

- the output of which fed to file

Note that I didn't use any for loops or variables, the shell did the right thing for me.

Read the man pages for each of those commands.

set -o vi or set -o emacs (or their equivalent in .inputrc) helps a lot when you compose things incrementally. esc-k k k (etc) is your friend if you set -o vi.

Read man bash. It will take you a long time. For today, read the section on READLINE. While in man bash, search for the word READLINE at the front of the line, like this:

/^READLINE

Slash = search

^ = anchor the search to the front of the line

READLINE = what you're searching for in the current man page.

For now, all you need in your ~/.inputrc file is:

set editing-mode vi

This will give you vi command line editing in bash, as well as any other program that uses readline, like the python REPL.

For more info on .inputrc,

  $ man readline
which is documentation for the C interface to readline, but is mostly about how readline is used by a user. For example, in man readline

/VI Mode bindings

gives you all your command line editing commands when you use vi mode.

Get a mostly table of contents of man bash, for your searching pleasure:

  $ man -P cat bash |egrep -v "^ " |egrep -o "^[^ ]+"
Sort it:

  $ man -P cat bash |egrep -v "^ " |egrep -o "^[^ ]+" |sort

Re: Ask HN: how did you learn the command line?

#50

I came to answer your question and say that when I started computing there was only the command line - there were no windows, effectively no graphics, and the only thing you could do was type commands. But then you ask if there are tutorials, and that I can't help you with. Having said that, I tried this search: http://www.google.co.uk/search?q=command+line+tutorial and I got lots of hits, including these: * http://w…

Me too, that's all there was. And that may be the answer: only allow yourself the command line for longer and longer periods of time. Force yourself to learn it. I really like this book, even today: http://shop.oreilly.com/product/9780596003302.do The key to being proficient at the command line (as distinct from writing shell scripts) is to think of it as composition. For example, run this: $ file $(which $(man -k py…

And ...

I realized/remembered while reading the other comments that knowing what's available is a necessary part of "just use the command line a lot."

So try this, to get a good list of what's available (and for more command line composition)

  $ man -k $(ls -1 /usr/bin |egrep -v "\[") 2>&1 |egrep -v "nothing appropriate"
See if you can figure out what 2>&1 does (it's a very common idiom, probably easy to find), and figure out why it's needed here.

That's a long list of stuff, look at it a page at a time:

  $ man -k $(ls -1 /usr/bin |egrep -v "\[") 2>&1 |egrep -v "nothing appropriate" |less
That's still a lot of stuff, save it off in a file in your home directory for later:

  $ man -k $(ls -1 /usr/bin |egrep -v "\[") 2>&1 |egrep -v "nothing appropriate" > ~/wholelottacommands.txt
Post reply on HN