Shell commands

CommandOptionsLesson
ls

Show this command by itself; introduces filenames and directories.

filenames

Then show it with filenames as arguments, which is not a lot of use in itself, but preparatory for the next one.

*.c or whatever suits your example directory

Then wildcards, thus introducing wildcard expansion. Explain that this is done by the shell, not by ls itself, which is behaving just as it did when you gave it individual filenames.

-l

Introduce the idea of options, and the usual syntax and mnemonic value of them. Introduce the idea of file ownership and permissions; perhaps a brief mention of execute permissions. (Probably gloss over groups at this stage.) With options like this, giving individual filenames becomes useful again.

-a

Introduce . and .., and the hierachical directory structure. Then show listing of absolute pathnames, such as ls /etc/

-R

More about the hierarchical directory structure.

-1

Explain that this is useful for feeding the output into other programs.

-tl, -rtl

Explain about the file timestamps.

cd, pwd

Introduce the idea of the working directory.

more

Introduce the | syntax.

tail

Another thing to use in pipes

grep

Introduce the idea of storing data in a line-based file

-i

Ignore case -- often useful

-l

Locate which files a string occurs in.

-n

Give the line numbers

-v

Negative output

sort

Another useful pipeline element.

This is a good stage at which to introduce redirection of input/output from/to files.

-u

Makes a set from a collection

+2 etc

Sorts by different columns

echo almost anything

A built-in command -- explain the difference between this and commands that run programs. Explain why cd must also be a built-in command.

*.c

Re-iterate that it is the shell that expands wildcards, not programs such as ls.

$PATH

Introduce the idea of environment variables, explaining that some of them, such as PATH, are used by the system, but you can also make your own.

which ls and other program names

Explain that, like the shell itself, this searches the path.

``

Introduce the shell backquote syntax, first using echo `which ls` to demonstrate it, and then putting it to real use with ls -l `which ls`.


[Operating Systems] To me Last modified: Thu Nov 24 12:24:48 GMT 2005