Skip to content

Commit

Permalink
Converting shell lesson Markdown files to use div + fence block
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson authored and wking committed Dec 4, 2014
1 parent 6525961 commit a6c41cc
Show file tree
Hide file tree
Showing 6 changed files with 753 additions and 369 deletions.
198 changes: 132 additions & 66 deletions 01-filedir.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Several commands are frequently used to create, inspect, rename, and delete file
To start exploring them,
let's open a shell window:

<pre class="in">
<div class="in" markdown="1">
~~~
$
</pre>
~~~
</div>

The dollar sign is a [prompt](../../gloss.html#prompt),
which shows us that the shell is waiting for input;
Expand All @@ -40,12 +42,16 @@ The command's output is the ID of the current user,
i.e.,
it shows us who the shell thinks we are:

<pre class="in">
<div class="in" markdown="1">
~~~
$ whoami
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
vlad
</pre>
~~~
</div>

More specifically, when we type `whoami` the shell:

Expand All @@ -67,12 +73,16 @@ Here,
the computer's response is `/users/vlad`,
which is Vlad's [home directory](../../gloss.html#home-directory):

<pre class="in">
<div class="in" markdown="1">
~~~
$ pwd
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
/users/vlad
</pre>
~~~
</div>

> #### Alphabet Soup
>
Expand Down Expand Up @@ -126,14 +136,18 @@ which is why `vlad` is the last part of the directory's name.
Let's see what's in Vlad's home directory by running `ls`,
which stands for "listing":

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
bin data mail music
notes.txt papers pizza.cfg solar
solar.pdf swc
</pre>
~~~
</div>

<img src="img/vlad-homedir.svg" alt="Vlad's Home Directory" />

Expand All @@ -142,14 +156,18 @@ arranged neatly into columns.
We can make its output more comprehensible by using the [flag](../../gloss.html#command-line-flag) `-F`,
which tells `ls` to add a trailing `/` to the names of directories:

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls -F
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
bin/ data/ mail/ music/
notes.txt papers/ pizza.cfg solar/
solar.pdf swc/
</pre>
~~~
</div>

Here,
we can see that `/users/vlad` contains seven [sub-directories](../../gloss.html#sub-directory).
Expand Down Expand Up @@ -188,13 +206,17 @@ the command `ls` with the parameters `-F` and `data`.
The second parameter&mdash;the one *without* a leading dash&mdash;tells `ls` that
we want a listing of something other than our current working directory:

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls -F data
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
amino-acids.txt elements/ morse.txt
pdb/ planets.txt sunspot.txt
</pre>
~~~
</div>

The output shows us that there are four text files and two sub-sub-directories.
Organizing things hierarchically in this way helps us keep track of our work:
Expand All @@ -212,13 +234,17 @@ rather than from the root of the file system.
If we run `ls -F /data` (*with* a leading slash) we get a different answer,
because `/data` is an [absolute path](../../gloss.html#absolute-path):

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls -F /data
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
access.log backup/ hardware.cfg
network.cfg
</pre>
~~~
</div>

The leading `/` tells the computer to follow the path from the root of the filesystem,
so it always refers to exactly one directory,
Expand All @@ -229,70 +255,96 @@ Before we do this,
`pwd` shows us that we're in `/users/vlad`,
and `ls` without any parameters shows us that directory's contents:

<pre class="in">
<div class="in" markdown="1">
~~~
$ pwd
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
/users/vlad
</pre>
<pre class="in">
~~~
</div>
<div class="in" markdown="1">
~~~
$ ls
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
bin/ data/ mail/ music/
notes.txt papers/ pizza.cfg solar/
solar.pdf swc/
</pre>
~~~
</div>

We can use `cd` followed by a directory name to change our working directory.
`cd` stands for "change directory",
which is a bit misleading:
the command doesn't change the directory,
it changes the shell's idea of what directory we are in.

<pre class="in">
<div class="in" markdown="1">
~~~
$ cd data
</pre>
~~~
</div>

`cd` doesn't print anything,
but if we run `pwd` after it, we can see that we are now in `/users/vlad/data`.
If we run `ls` without parameters now,
it lists the contents of `/users/vlad/data`,
because that's where we now are:

<pre class="in">
<div class="in" markdown="1">
~~~
$ pwd
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
/users/vlad/data
</pre>
<pre class="in">
~~~
</div>
<div class="in" markdown="1">
~~~
$ ls
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
amino-acids.txt elements/ morse.txt
pdb/ planets.txt sunspot.txt
</pre>
~~~
</div>

We now know how to go down the directory tree:
how do we go up?
We could use an absolute path:

<pre class="in">
<div class="in" markdown="1">
~~~
$ cd /users/vlad
</pre>
~~~
</div>

but it's almost always simpler to use `cd ..` to go up one level:

<pre class="in">
<div class="in" markdown="1">
~~~
$ pwd
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
/users/vlad/data
</pre>
<pre class="in">
~~~
</div>
<div class="in" markdown="1">
~~~
$ cd ..
</pre>
~~~
</div>

`..` is a special directory name meaning
"the directory containing this one",
Expand All @@ -301,24 +353,32 @@ the [parent](../../gloss.html#parent-directory) of the current directory.
Sure enough,
if we run `pwd` after running `cd ..`, we're back in `/users/vlad`:

<pre class="in">
<div class="in" markdown="1">
~~~
$ pwd
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
/users/vlad
</pre>
~~~
</div>

The special directory `..` doesn't usually show up when we run `ls`.
If we want to display it, we can give `ls` the `-a` flag:

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls -F -a
</pre>
<pre class="out">
~~~
</div>
<div class="out" markdown="1">
~~~
./ ../ bin/ data/
mail/ music/ notes.txt papers/
pizza.cfg solar/ solar.pdf swc/
</pre>
~~~
</div>

`-a` stands for "show all";
it forces `ls` to show us file and directory names that begin with `.`,
Expand Down Expand Up @@ -377,24 +437,30 @@ All 1520 files will go into the same directory.
If she is in her home directory,
Nelle can see what files she has using the command:

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls north-pacific-gyre/2012-07-03/
</pre>
~~~
</div>

This is a lot to type,
but she can let the shell do most of the work.
If she types:

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls no
</pre>
~~~
</div>

and then presses tab,
the shell automatically completes the directory name for her:

<pre class="in">
<div class="in" markdown="1">
~~~
$ ls north-pacific-gyre/
</pre>
~~~
</div>

If she presses tab again,
Bash will add `2012-07-03/` to the command,
Expand Down
Loading

0 comments on commit a6c41cc

Please sign in to comment.