Skip to content

Commit

Permalink
HTML update
Browse files Browse the repository at this point in the history
  • Loading branch information
gdevenyi committed Jun 13, 2016
1 parent 35fa387 commit 229d8b6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
3 changes: 2 additions & 1 deletion 01-filedir.html
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ <h2 id="ls-reading-comprehension"><span class="glyphicon glyphicon-pencil"></spa
<h2 id="exploring-more-ls-arguments"><span class="glyphicon glyphicon-pencil"></span>Exploring more <code>ls</code> arguments</h2>
</div>
<div class="panel-body">
<p>What does the command <code>ls</code> do when used with the <code>-s</code> and <code>-h</code> arguments?</p>
<p>What does the command <code>ls</code> do when used with the <code>-l</code> and <code>-h</code> arguments?</p>
<p>Some of its output is about properties that we do not cover in this lesson (such as file permissions and ownership), but the rest should be useful nevertheless.</p>
</div>
</section>
<section class="challenge panel panel-success">
Expand Down
36 changes: 18 additions & 18 deletions 02-create.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,26 @@ <h2 id="which-editor"><span class="glyphicon glyphicon-pushpin"></span>Which Edi
<p>No matter what editor you use, you will need to know where it searches for and saves files. If you start it from the shell, it will (probably) use your current working directory as its default location. If you use your computer’s start menu, it may want to save files in your desktop or documents directory instead. You can change this by navigating to another directory the first time you “Save As…”</p>
</div>
</aside>
<p>Let’s type in a few lines of text. Once we’re happy with out text, we can press Ctrl-O (press the Ctrl key and, while holding it down, press the O key) to write our data to disk (we’ll be asked what file we want to save this to: press Return to accept the suggested default of <code>draft.txt</code>).</p>
<p>Let’s type in a few lines of text. Once we’re happy with our text, we can press <code>Ctrl-O</code> (press the Ctrl or Control key and, while holding it down, press the O key) to write our data to disk (we’ll be asked what file we want to save this to: press Return to accept the suggested default of <code>draft.txt</code>).</p>
<div class="figure">
<img src="fig/nano-screenshot.png" alt="Nano in action" />
<p class="caption">Nano in action</p>
</div>
<p>Once our file is saved, we can use Ctrl-X to quit the editor and return to the shell.</p>
<p>Once our file is saved, we can use <code>Ctrl-X</code> to quit the editor and return to the shell.</p>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2 id="ctrl-control-key"><span class="glyphicon glyphicon-pushpin"></span>Ctrl, “Control”, key</h2>
<h2 id="control-ctrl-or-key"><span class="glyphicon glyphicon-pushpin"></span>Control, ctrl, or ^ key</h2>
</div>
<div class="panel-body">
<p>The Ctrl key is called the “Control” key. There are various ways in which using the Ctrl key may be described. For example, you may see an instruction to press the Ctrl key and, while holding it down, press the X key, described as any of:</p>
<p>The Control key is also called the “Ctrl” key. There are various ways in which using the Control key may be described. For example, you may see an instruction to press the Control key and, while holding it down, press the X key, described as any of:</p>
<ul>
<li>Ctrl-X</li>
<li>Ctrl+X</li>
<li>Control-X</li>
<li>Control+X</li>
<li><code>Control-X</code></li>
<li><code>Control+X</code></li>
<li><code>Ctrl-X</code></li>
<li><code>Ctrl+X</code></li>
<li><code>^X</code></li>
</ul>
<p>In nano, along the bottom of the screen you’ll see <code>^G Get Help ^O WriteOut</code>. This means that you can use <code>Control-G</code> to get help and <code>Control-O</code> to save your file.</p>
</div>
</aside>
<p><code>nano</code> doesn’t leave any output on the screen after it exits, but <code>ls</code> now shows that we have created a file called <code>draft.txt</code>:</p>
Expand Down Expand Up @@ -116,21 +117,20 @@ <h2 id="deleting-is-forever"><span class="glyphicon glyphicon-pushpin"></span>De
<p>If we try to remove the entire <code>thesis</code> directory using <code>rm thesis</code>, we get an error message:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">rm</span> thesis</code></pre></div>
<pre class="error"><code>rm: cannot remove `thesis&#39;: Is a directory</code></pre>
<p>This happens because <code>rm</code> only works on files, not directories. The right command is <code>rmdir</code>, which is short for “remove directory”. It doesn’t work yet either, though, because the directory we’re trying to remove isn’t empty:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">rmdir</span> thesis</code></pre></div>
<pre class="error"><code>rmdir: failed to remove `thesis&#39;: Directory not empty</code></pre>
<p>This little safety feature can save you a lot of grief, particularly if you are a bad typist. To really get rid of <code>thesis</code> we must first delete the file <code>draft.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">rm</span> thesis/draft.txt</code></pre></div>
<p>The directory is now empty, so <code>rmdir</code> can delete it:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">rmdir</span> thesis</code></pre></div>
<p>This happens because <code>rm</code> by default only works on files, not directories.</p>
<p>To really get rid of <code>thesis</code> we must also delete the file <code>draft.txt</code>. We can do this with the <a href="https://en.wikipedia.org/wiki/Recursion">recursive</a> option for <code>rm</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">rm</span> -r thesis</code></pre></div>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2 id="with-great-power-comes-great-responsibility"><span class="glyphicon glyphicon-pushpin"></span>With Great Power Comes Great Responsibility</h2>
</div>
<div class="panel-body">
<p>Removing the files in a directory just so that we can remove the directory quickly becomes tedious. Instead, we can use <code>rm</code> with the <code>-r</code> flag (which stands for “recursive”):</p>
<pre><code>$ rm -r thesis</code></pre>
<p>This removes everything in the directory, then the directory itself. If the directory contains sub-directories, <code>rm -r</code> does the same thing to them, and so on. It’s very handy, but can do a lot of damage if used without care.</p>
<p>Removing the files in a directory recursively can be very dangerous operation. If we’re concerned about what we might be deleting we can add the “interactive” flag <code>-i</code> to <code>rm</code> which will ask us for confirmation before each step</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">rm</span> -r -i thesis
<span class="kw">rm</span>: descend into directory ‘thesis’? y
<span class="kw">rm</span>: remove regular file ‘thesis/draft.txt’? y
<span class="kw">rm</span>: remove directory ‘thesis’? y</code></pre></div>
<p>This removes everything in the directory, then the directory itself, asking at each step for you to confirm the deletion.</p>
</div>
</aside>
<p>Let’s create that directory and file one more time. (Note that this time we’re running <code>nano</code> with the path <code>thesis/draft.txt</code>, rather than going into the <code>thesis</code> directory and running <code>nano</code> on <code>draft.txt</code> there.)</p>
Expand Down
28 changes: 18 additions & 10 deletions 06-find.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,24 @@ <h2 id="wildcards"><span class="glyphicon glyphicon-pushpin"></span>Wildcards</h
<p class="caption">File Tree for Find Example</p>
</div>
<p>Nelle’s <code>writing</code> directory contains one file called <code>haiku.txt</code> and four subdirectories: <code>thesis</code> (which contains a sadly empty file, <code>empty-draft.md</code>), <code>data</code> (which contains two files <code>one.txt</code> and <code>two.txt</code>), a <code>tools</code> directory that contains the programs <code>format</code> and <code>stats</code>, and a subdirectory called <code>old</code>, with a file <code>oldtool</code>.</p>
<p>For our first command, let’s run <code>find . -type d</code>. As always, the <code>.</code> on its own means the current working directory, which is where we want our search to start; <code>-type d</code> means “things that are directories”. Sure enough, <code>find</code>’s output is the names of the five directories in our little tree (including <code>.</code>):</p>
<p>For our first command, let’s run <code>find .</code>.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> .</code></pre></div>
<pre class="output"><code>.
./old
./old/.gitkeep
./data
./data/one.txt
./data/two.txt
./tools
./tools/format
./tools/old
./tools/old/oldtool
./tools/stats
./haiku.txt
./thesis
./thesis/empty-draft.md</code></pre>
<p>As always, the <code>.</code> on its own means the current working directory, which is where we want our search to start. <code>find</code>’s output is the names of every file <strong>and</strong> directory under the current working directory. This can seen useless at first but <code>find</code> has many options to filter the output and in this lesson we will discovery some.</p>
<p>The first option in our list is <code>-type d</code> that means “things that are directories”. Sure enough, <code>find</code>’s output is the names of the five directories in our little tree (including <code>.</code>):</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> . -type d</code></pre></div>
<pre class="output"><code>./
./data
Expand All @@ -165,15 +182,6 @@ <h2 id="wildcards"><span class="glyphicon glyphicon-pushpin"></span>Wildcards</h
./thesis/empty-draft.md
./data/one.txt
./data/two.txt</code></pre>
<p><code>find</code> automatically goes into subdirectories, their subdirectories, and so on to find everything that matches the pattern we’ve given it. If we don’t want it to, we can use <code>-maxdepth</code> to restrict the depth of search:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> . -maxdepth 1 -type f</code></pre></div>
<pre class="output"><code>./haiku.txt</code></pre>
<p>The opposite of <code>-maxdepth</code> is <code>-mindepth</code>, which tells <code>find</code> to only report things that are at or below a certain depth. <code>-mindepth 2</code> therefore finds all the files that are two or more levels below us:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> . -mindepth 2 -type f</code></pre></div>
<pre class="output"><code>./data/one.txt
./data/two.txt
./tools/format
./tools/stats</code></pre>
<p>Now let’s try matching by name:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> . -name *.txt</code></pre></div>
<pre class="output"><code>./haiku.txt</code></pre>
Expand Down

0 comments on commit 229d8b6

Please sign in to comment.