Command Line 2

=Introduction= You've taken the Command Line class. You've QC'd a couple of boxen, and now you've built one. In the meantime, you've forgotten everything you learned in Command Line, except (I hope), tab completion. It's time to learn how it all works, fits together, and how to make sense of it all. Then you can go on to all the other topics in From $ to #.

=Lexing a command line= guest@freekbox:~$ ls -la --sort=size -r -w 100 /home/lab* /home/class*

Scared? It's simpler when you know how to lex. Lex, the verb, means to break a flow of information into meaningful symbols. It's a term specific to linguistics and computer science, so you may not know it, but you do it all the time. When reading this sentence you recognize spaces and turn the letters around the spaces into separate words. You could lex on commas, and,then,the,sentence,would,look,like,this. We lex in aural conversation as well, though the spaces aren't visible, they're something we have to be taught. This is why the last step of fluency in a foreign language is the most difficult: knowing when they're saying "heat it", as opposed to "He did."

Despite all the other strange characters in a regular command line (the /, the -, the *, etc), we lex command line arguments with spaces. So let's look at the different pieces of the above command

ls -la --sort=size -r -w 100 /home/lab/* /home/class/*

The most important of these is always the first one. Here's why.

=Programs are a field of machines=

Imagine, for a moment, that you are outside the Matrix, looking out at the field of machines that runs Zion. It is overwhelming. They seem to all interact and interrelate in bizarre ways. People are going through bizarre motions as they tend to machines because this is the way they have been taught.

You discover a simpler way. It turns out that, though they seem to interrelate, each machine is its own entity, and when you are looking at the machine, it has its directions for how to use it printed on the side. Though now you realize you need to remember where all the machines are called, you understand that when you get to the machine you need, the instructions are in front of you.

There's a field of machines in Unix. They're called programs, executables, or binaries (all the same thing). Some coder put together a project in which he, she, it (he from now on) figured out what he wanted the program to do and wrote that. Then he compiled it into a binary and installed it somewhere. This binary can have its own system of rules and way of thinking, but that will be documented in the man page. Soon you'll know enough to start reading them.

=Parsing a command, part 1=

Imagine momentarily that we put the verb first in English grammar. Talk like Yoda, we would. Know, however, immediately, we would, meant to convey what action the sentence did.

Command line talks like Yoda. The first word is the command, the action. The binary, or the machine, in the above. So

guest@freekbox:~$ ls -la --sort=size -r -w 100 /home/lab* /home/class* The only piece we care about immediately is ls. ls is a command to list files in a directory (we'll get there in a moment). To know anything else about the command line above we have to read man ls to find out how ls expects arguments. When we read ls, we find out that -l means one thing, -a means another, --sort=size means sort files by size, -r means recursive, -w gets passed the 100 and means format the output to 100 columns, and the last two pieces are the directories/files we want listed. The *s I'll explain in a bit, in Parsing Part 2.

=Paths/Filesystem introduction=

=Parsing, Part 2=

=Bash is a shell=

=A handful of commands=

=The pipe=

=How do you do this?=