Skip to content

Commit

Permalink
Switching to explicit <pre> blocks with styles instead of fences
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson authored and wking committed Nov 6, 2014
1 parent 01cd6db commit e6c92a5
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 245 deletions.
102 changes: 66 additions & 36 deletions 01-filedir.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ 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">
$
~~~
</pre>

The dollar sign is a [prompt](../../gloss.html#prompt),
which shows us that the shell is waiting for input;
Expand All @@ -41,10 +41,12 @@ 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">
$ whoami
</pre>
<pre class="out">
vlad
~~~
</pre>

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

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

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

> #### Alphabet Soup
>
Expand Down Expand Up @@ -123,12 +127,14 @@ 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">
$ ls
</pre>
<pre class="out">
bin data mail music
notes.txt papers pizza.cfg solar
solar.pdf swc
~~~
</pre>

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

Expand All @@ -137,12 +143,14 @@ 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">
$ ls -F
</pre>
<pre class="out">
bin/ data/ mail/ music/
notes.txt papers/ pizza.cfg solar/
solar.pdf swc/
~~~
</pre>

Here,
we can see that `/users/vlad` contains seven [sub-directories](../../gloss.html#sub-directory).
Expand Down Expand Up @@ -181,11 +189,13 @@ 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">
$ ls -F data
</pre>
<pre class="out">
amino-acids.txt elements/ morse.txt
pdb/ planets.txt sunspot.txt
~~~
</pre>

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 @@ -203,11 +213,13 @@ 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">
$ ls -F /data
</pre>
<pre class="out">
access.log backup/ hardware.cfg
network.cfg
~~~
</pre>

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 @@ -218,56 +230,70 @@ 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">
$ pwd
</pre>
<pre class="out">
/users/vlad
</pre>
<pre class="in">
$ ls
</pre>
<pre class="out">
bin/ data/ mail/ music/
notes.txt papers/ pizza.cfg solar/
solar.pdf swc/
~~~
</pre>

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">
$ cd data
~~~
</pre>

`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">
$ pwd
</pre>
<pre class="out">
/users/vlad/data
</pre>
<pre class="in">
$ ls
</pre>
<pre class="out">
amino-acids.txt elements/ morse.txt
pdb/ planets.txt sunspot.txt
~~~
</pre>

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

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

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

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

`..` is a special directory name meaning
"the directory containing this one",
Expand All @@ -276,20 +302,24 @@ 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">
$ pwd
</pre>
<pre class="out">
/users/vlad
~~~
</pre>

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">
$ ls -F -a
</pre>
<pre class="out">
./ ../ bin/ data/
mail/ music/ notes.txt papers/
pizza.cfg solar/ solar.pdf swc/
~~~
</pre>

`-a` stands for "show all";
it forces `ls` to show us file and directory names that begin with `.`,
Expand Down Expand Up @@ -348,24 +378,24 @@ 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">
$ ls north-pacific-gyre/2012-07-03/
~~~
</pre>

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

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

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

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

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

0 comments on commit e6c92a5

Please sign in to comment.