<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Linux and the command line 101 · Network Doodles</title><link>https://networkdoodles.com/labs/linux-cli-101/</link><description>Hands-on Linux for network engineers: find your way around the filesystem, read and edit files, build pipelines with grep, fix permissions, stop a runaway process, log in with SSH keys, write two small Bash scripts, and troubleshoot a web service with ip, ss, curl, dig, traceroute and tcpdump. In your browser, nothing to install.</description><language>en-us</language><managingEditor>David Henderson</managingEditor><lastBuildDate>Mon, 16 Nov 2026 09:00:00 -0500</lastBuildDate><atom:link href="https://networkdoodles.com/labs/linux-cli-101/index.xml" rel="self" type="application/rss+xml"/><item><title>Catch it on the wire</title><link>https://networkdoodles.com/labs/linux-cli-101/task-8-3/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-8-3/</guid><description> new to this? step by stepbeginner On ws1: sudo tcpdump -n -i eth1 -w web.pcap port 8080 &amp;, then curl -s http://srv1:8080/, then fg and Ctrl+C. tcpdump -n -r web.pcap: read it. exit, then in the codespace: scp ws1:web.pcap captures/. Challenge: from the capture, ws1’s port and the packet count. Fill in answers/8.3.yml, then make check T=8.3. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li>On ws1: <code>sudo tcpdump -n -i eth1 -w web.pcap port 8080 &amp;</code>, then <code>curl -s http://srv1:8080/</code>, then <code>fg</code> and <kbd>Ctrl</kbd>+<kbd>C</kbd>.</li>
<li><code>tcpdump -n -r web.pcap</code>: read it.</li>
<li><code>exit</code>, then in the codespace: <code>scp ws1:web.pcap captures/</code>.</li>
<li>Challenge: from the capture, ws1&rsquo;s port and the packet count. Fill in answers/8.3.yml, then <code>make check T=8.3</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>tcpdump: Wireshark without the window</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="why-tcpdump">Why tcpdump</h3>
<p>A server you reach with SSH has no screen, so Wireshark can&rsquo;t run there. <strong>tcpdump</strong> captures the same packets in
a terminal. It&rsquo;s on almost every Linux machine, and its files open in Wireshark later.</p>
<table>
  <thead>
      <tr>
          <th>Option</th>
          <th>Means</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>-i eth1</code></td>
          <td>capture on this interface</td>
      </tr>
      <tr>
          <td><code>-n</code></td>
          <td>show addresses and ports as numbers (don&rsquo;t look names up)</td>
      </tr>
      <tr>
          <td><code>-w file.pcap</code></td>
          <td>write the packets to a file instead of the screen</td>
      </tr>
      <tr>
          <td><code>-r file.pcap</code></td>
          <td>read a file instead of capturing</td>
      </tr>
      <tr>
          <td><code>-c 20</code></td>
          <td>stop after 20 packets</td>
      </tr>
      <tr>
          <td><code>port 8080</code>, <code>host srv1</code></td>
          <td>a <strong>capture filter</strong>: only keep packets that match</td>
      </tr>
  </tbody>
</table>
<p>Capturing needs root, so it&rsquo;s <code>sudo tcpdump</code>. Reading a file anyone can read doesn&rsquo;t.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> tcpdump -w saves a capture; tcpdump -r reads it; a filter like port 8080 keeps only what you need.</p>
<h3 id="a-capture-in-the-background">A capture in the background</h3>
<p>You need tcpdump capturing <em>while</em> curl runs. Chapter 5 had the answer: start tcpdump with <code>&amp;</code>, so it runs in the
background, run curl, then bring tcpdump back with <code>fg</code> and stop it with <kbd>Ctrl</kbd>+<kbd>C</kbd>. It writes
the file and says how many packets it captured.</p>
<h3 id="reading-one-line">Reading one line</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">05:52:31.037441 IP 192.168.10.10.53380 &gt; 192.168.20.10.8080: Flags [S], seq 2218734704, win 64240, ...
</span></span></code></pre></div><p>When it was seen, then <strong>source address.port &gt; destination address.port</strong>, then TCP&rsquo;s flags: <code>[S]</code> is a SYN,
<code>[S.]</code> a SYN-ACK, <code>[.]</code> an ACK, <code>[P.]</code> data, <code>[F.]</code> a FIN. <a href="/lessons/wireshark-101/tcp/">Wireshark 101</a> reads
the same connection field by field.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>One request, every packet</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">netops@ws1:~$ tcpdump -n -r web.pcap
</span></span><span class="line"><span class="cl">05:52:31.037441 IP 192.168.10.10.53380 &gt; 192.168.20.10.8080: Flags [S], seq 2218734704, win 64240, options [mss 1460,sackOK,TS val 1308440284 ecr 0,nop,wscale 7], length 0
</span></span><span class="line"><span class="cl">05:52:31.037537 IP 192.168.20.10.8080 &gt; 192.168.10.10.53380: Flags [S.], seq 162168246, ack 2218734705, win 65160, options [mss 1460,sackOK,TS val 589802733 ecr 1308440284,nop,wscale 7], length 0
</span></span><span class="line"><span class="cl">05:52:31.037547 IP 192.168.10.10.53380 &gt; 192.168.20.10.8080: Flags [.], ack 1, win 502, options [nop,nop,TS val 1308440284 ecr 589802733], length 0
</span></span><span class="line"><span class="cl">05:52:31.037610 IP 192.168.10.10.53380 &gt; 192.168.20.10.8080: Flags [P.], seq 1:74, ack 1, win 502, options [nop,nop,TS val 1308440284 ecr 589802733], length 73: HTTP: GET / HTTP/1.1
</span></span><span class="line"><span class="cl">...
</span></span><span class="line"><span class="cl">05:52:31.044467 IP 192.168.10.10.53380 &gt; 192.168.20.10.8080: Flags [F.], seq 74, ack 217, win 501, options [nop,nop,TS val 1308440291 ecr 589802740], length 0
</span></span></code></pre></div><p>The three-way handshake, the <code>GET /</code> (73 bytes), the reply, and the close. Your times, ports and sequence numbers
will differ.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Capture, read, copy</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>On ws1, start a capture in the background. tcpdump says it&rsquo;s listening:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh ws1
</span></span><span class="line"><span class="cl">sudo tcpdump -n -i eth1 -w web.pcap port <span class="m">8080</span> <span class="p">&amp;</span>
</span></span></code></pre></div></li>
<li>
<p>Make the traffic, then stop the capture:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -s http://srv1:8080/
</span></span><span class="line"><span class="cl"><span class="nb">fg</span>
</span></span></code></pre></div><p>Press <kbd>Ctrl</kbd>+<kbd>C</kbd>. tcpdump prints <em>N packets captured</em>.</p>
</li>
<li>
<p>Read it back. <code>ls -l</code> shows the file belongs to a user called <strong>tcpdump</strong>: tcpdump starts as root to open
the interface, then gives root up and runs as its own user. The file is <code>-rw-r--r--</code>, so you can read it
without sudo:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ls -l web.pcap
</span></span><span class="line"><span class="cl">tcpdump -n -r web.pcap
</span></span><span class="line"><span class="cl"><span class="nb">exit</span>
</span></span></code></pre></div></li>
<li>
<p>In the codespace, copy it into the lab&rsquo;s <code>captures/</code> folder:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">scp ws1:web.pcap captures/
</span></span><span class="line"><span class="cl">tcpdump -n -r captures/web.pcap <span class="p">|</span> head -n <span class="m">3</span>
</span></span></code></pre></div><p>The same packets, now on your side. Right-click the file in the Explorer and <strong>Download</strong> it to open it in your
own Wireshark.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> Capture in the background, make the traffic, stop it with fg and Ctrl+C, then scp the file home.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Read your capture</h2>
  </header>
  <div class="lab-stage-body">
    <p>From <strong>your</strong> captures/web.pcap:</p>
<ol>
<li><code>client_port</code>: the port ws1 used for this connection, from the first packet, the SYN.</li>
<li><code>packets</code>: how many packets the capture holds.</li>
</ol>
<p>Then <code>make check T=8.3</code>. It reads your file, so the answers are yours, not the guide&rsquo;s.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>In <code>192.168.10.10.53380 &gt; 192.168.20.10.8080</code>, the last number of each address is its port. ws1&rsquo;s is on the left
of the <code>&gt;</code> in the SYN.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>tcpdump -n -r captures/web.pcap | wc -l</code> counts the lines, one per packet.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">tcpdump -n -r captures/web.pcap 2&gt;/dev/null <span class="p">|</span> head -n <span class="m">1</span>
</span></span><span class="line"><span class="cl">tcpdump -n -r captures/web.pcap 2&gt;/dev/null <span class="p">|</span> wc -l
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">client_port: 53380      # yours is different</span><span class="p">:</span><span class="w"> </span><span class="l">ws1 picks a new one for every connection</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">packets</span><span class="p">:</span><span class="w"> </span><span class="m">12</span><span class="w">
</span></span></span></code></pre></div><p>tcpdump prints <em>reading from file &hellip;</em> on stderr, which is why <code>2&gt;/dev/null</code> keeps it out of the count. Twelve is
typical for one small request: three for the handshake, the request and its ACK, the reply in two parts and their
ACKs, then a FIN each way and the last ACK. A different count is fine, as long as it&rsquo;s what your file holds.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Refused</title><link>https://networkdoodles.com/labs/linux-cli-101/task-8-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-8-2/</guid><description> new to this? step by stepbeginner On ws1: curl -v http://srv1:8080/. Read the line that says failed. On srv1: curl http://localhost:8080/ works. ss -tlnp: which address is port 8080 on? sudo nano /etc/labweb.conf, change BIND, then sudo labweb restart, and ss -tlnp again. On ws1: curl http://srv1:8080/ gets the page. Fill in answers/8.2.yml, then make check T=8.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li>On ws1: <code>curl -v http://srv1:8080/</code>. Read the line that says <em>failed</em>.</li>
<li>On srv1: <code>curl http://localhost:8080/</code> works. <code>ss -tlnp</code>: which address is port 8080 on?</li>
<li><code>sudo nano /etc/labweb.conf</code>, change <code>BIND</code>, then <code>sudo labweb restart</code>, and <code>ss -tlnp</code> again.</li>
<li>On ws1: <code>curl http://srv1:8080/</code> gets the page. Fill in answers/8.2.yml, then <code>make check T=8.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Is it the network, or the service?</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="one-error-many-causes">One error, many causes</h3>
<p>&ldquo;It doesn&rsquo;t work&rdquo; from another machine can be DNS, a route, a firewall, the service being down, or the service
not listening where you think it is. The trick is to split the problem in two: try it <strong>from the server itself</strong>
first. If it works there and not from outside, the service is fine and the question is the path to it, or how it&rsquo;s
listening.</p>
<h3 id="curl--v-shows-each-step">curl -v shows each step</h3>
<p><code>curl -v</code> prints what it&rsquo;s doing, line by line, before it prints the page:</p>
<table>
  <thead>
      <tr>
          <th>Lines starting</th>
          <th>Tell you</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>* Host srv1:8080 was resolved</code> / <code>* IPv4: ...</code></td>
          <td>DNS worked, and the address it used</td>
      </tr>
      <tr>
          <td><code>*   Trying 192.168.20.10:8080...</code></td>
          <td>it&rsquo;s opening a TCP connection</td>
      </tr>
      <tr>
          <td><code>* Connected to ...</code></td>
          <td>TCP worked: something is listening there</td>
      </tr>
      <tr>
          <td><code>&gt; GET / HTTP/1.1</code></td>
          <td>what curl sent</td>
      </tr>
      <tr>
          <td><code>&lt; HTTP/1.0 200 OK</code></td>
          <td>what came back</td>
      </tr>
  </tbody>
</table>
<p>Where those lines stop is where the problem is. <strong>Connection refused</strong> means the packet got there, and the
machine answered <em>nothing is listening on that port</em>. That&rsquo;s different from silence (a timeout), which usually
means a firewall or a route.</p>
<h3 id="ss-whos-listening-and-where">ss: who&rsquo;s listening, and where</h3>
<p><code>ss -tlnp</code> lists <strong>t</strong>CP sockets that are <strong>l</strong>istening, with <strong>n</strong>umbers instead of names, and the <strong>p</strong>rocess
(that last part needs <code>sudo</code> for other users&rsquo; processes). The <em>Local Address:Port</em> column says which address
the service accepts connections on:</p>
<table>
  <thead>
      <tr>
          <th>Local address</th>
          <th>Accepts connections</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>127.0.0.1:8080</code></td>
          <td>only from the machine itself (the loopback)</td>
      </tr>
      <tr>
          <td><code>192.168.20.10:8080</code></td>
          <td>on that one address</td>
      </tr>
      <tr>
          <td><code>0.0.0.0:8080</code></td>
          <td>on every IPv4 address the machine has</td>
      </tr>
  </tbody>
</table>
<p class="lab-recap"><span class="mono">in one sentence</span> Try it on the server first; curl -v shows where it stops; ss -tlnp shows where a service listens.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>A refusal, step by step</h2>
  </header>
  <div class="lab-stage-body">
    <p><code>curl -v</code> from ws1 to a port where nothing listens on srv1:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">netops@ws1:~$ curl -v http://srv1:8081/
</span></span><span class="line"><span class="cl">* Host srv1:8081 was resolved.
</span></span><span class="line"><span class="cl">* IPv6: (none)
</span></span><span class="line"><span class="cl">* IPv4: 192.168.20.10
</span></span><span class="line"><span class="cl">*   Trying 192.168.20.10:8081...
</span></span><span class="line"><span class="cl">* connect to 192.168.20.10 port 8081 from 192.168.10.10 port 57930 failed: Connection refused
</span></span><span class="line"><span class="cl">* Failed to connect to srv1 port 8081 after 16 ms: Could not connect to server
</span></span><span class="line"><span class="cl">* closing connection #0
</span></span><span class="line"><span class="cl">curl: (7) Failed to connect to srv1 port 8081 after 16 ms: Could not connect to server
</span></span></code></pre></div><p>DNS worked (<code>192.168.20.10</code>), the route worked (the refusal came back), and the port is closed. The last line is
curl&rsquo;s summary: newer versions say <em>Could not connect to server</em>, and the <code>-v</code> line above it says why.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Make labweb answer ws1</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>From <strong>ws1</strong>, <code>curl -v http://srv1:8080/</code>. Which word does the <em>failed</em> line end with? That&rsquo;s <code>curl_said</code>.</li>
<li>On <strong>srv1</strong>, try the same with <code>curl http://localhost:8080/</code>. Then find out which address labweb is listening
on (<code>listen_before</code>).</li>
<li>Fix it in <code>/etc/labweb.conf</code>, restart labweb, and check again with <code>ss</code>: that&rsquo;s <code>listen_after</code>.</li>
<li>From <strong>ws1</strong>, <code>curl http://srv1:8080/</code> prints <em>Hello from srv1</em>.</li>
</ol>
<p>Then <code>make check T=8.2</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>ss -tlnp</code> on srv1. Find <code>:8080</code> in the <em>Local Address:Port</em> column, and read the address in front of it.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>/etc/labweb.conf</code> belongs to root, so <code>sudo nano /etc/labweb.conf</code>. <code>cat</code> it first: the setting has a name that
says what it is.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>A service reads its config when it starts, so a change does nothing until <code>sudo labweb restart</code>.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">netops@srv1:~$ ss -tlnp
</span></span><span class="line"><span class="cl">State  Recv-Q Send-Q Local Address:Port  Peer Address:PortProcess
</span></span><span class="line"><span class="cl">LISTEN 0      32         127.0.0.1:53         0.0.0.0:*
</span></span><span class="line"><span class="cl">LISTEN 0      32     192.168.20.10:53         0.0.0.0:*
</span></span><span class="line"><span class="cl">LISTEN 0      5          127.0.0.1:8080       0.0.0.0:*
</span></span><span class="line"><span class="cl">LISTEN 0      128          0.0.0.0:22         0.0.0.0:*
</span></span><span class="line"><span class="cl">LISTEN 0      4096      127.0.0.11:38163      0.0.0.0:*
</span></span><span class="line"><span class="cl">LISTEN 0      128             [::]:22            [::]:*
</span></span></code></pre></div><p>labweb is on <code>127.0.0.1</code>: it only accepts connections from srv1 itself. (<code>127.0.0.11</code> is Docker&rsquo;s own DNS
helper, and port 53 is srv1&rsquo;s DNS server.)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo nano /etc/labweb.conf      <span class="c1"># BIND=127.0.0.1  becomes  BIND=0.0.0.0</span>
</span></span><span class="line"><span class="cl">sudo labweb restart
</span></span><span class="line"><span class="cl">ss -tln
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">curl_said</span><span class="p">:</span><span class="w"> </span><span class="l">refused</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">listen_before</span><span class="p">:</span><span class="w"> </span><span class="m">127.0.0.1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">listen_after</span><span class="p">:</span><span class="w"> </span><span class="m">0.0.0.0</span><span class="w">
</span></span></span></code></pre></div><p><code>BIND=192.168.20.10</code> works too: it listens on srv1&rsquo;s network address only. This is one of the most common reasons
a service <em>works on the server</em> and nowhere else, and it&rsquo;s worth checking before you open a firewall ticket.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Where does it go?</title><link>https://networkdoodles.com/labs/linux-cli-101/task-8-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-8-1/</guid><description> new to this? step by stepbeginner ssh ws1, then ip -br addr and ip route: the management interface and the gateway. cat /etc/resolv.conf and dig srv1.lab (and dig +short srv1.lab). Challenge: ip route get 192.168.20.10 and traceroute -n srv1. exit, fill in answers/8.1.yml, then make check T=8.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>ssh ws1</code>, then <code>ip -br addr</code> and <code>ip route</code>: the management interface and the gateway.</li>
<li><code>cat /etc/resolv.conf</code> and <code>dig srv1.lab</code> (and <code>dig +short srv1.lab</code>).</li>
<li>Challenge: <code>ip route get 192.168.20.10</code> and <code>traceroute -n srv1</code>.</li>
<li><code>exit</code>, fill in answers/8.1.yml, then <code>make check T=8.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>From the Networking 101 lab, one level down</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="what-you-already-know">What you already know</h3>
<p>The <a href="/labs/networking-101-lab/">Networking 101 lab</a> had you read <code>ip addr</code>, <code>ip route</code>, <code>ping</code>, <code>traceroute</code> and
<code>dig</code> on its hosts. Here the same commands come with the options engineers type day to day, on a machine with two
networks, which is the usual case for servers.</p>
<table>
  <thead>
      <tr>
          <th>Command</th>
          <th>Answers</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>ip -br addr</code></td>
          <td>every interface and its address, one line each (<code>-br</code> is <em>brief</em>)</td>
      </tr>
      <tr>
          <td><code>ip route</code></td>
          <td>the routing table: where each network goes, and the default</td>
      </tr>
      <tr>
          <td><code>ip route get ADDRESS</code></td>
          <td>which route <em>this one address</em> would use: the gateway, the interface, and the source address</td>
      </tr>
      <tr>
          <td><code>dig NAME</code></td>
          <td>the full DNS answer: the question, the answer, the TTL, which server replied</td>
      </tr>
      <tr>
          <td><code>dig +short NAME</code></td>
          <td>just the address</td>
      </tr>
      <tr>
          <td><code>traceroute -n HOST</code></td>
          <td>each router on the way, as numbers (<code>-n</code>: don&rsquo;t look up names, it&rsquo;s faster)</td>
      </tr>
  </tbody>
</table>
<h3 id="two-networks-one-default">Two networks, one default</h3>
<p>ws1 has two interfaces. <code>eth0</code> is on the lab&rsquo;s <strong>management network</strong>, the one your codespace uses to reach it;
it has a route for that one network only. <code>eth1</code> goes to r1, and the <strong>default route</strong>, for everything else,
points at r1. <code>ip route get</code> shows that choice being made for one address, which is the quickest way to answer
<em>why is this traffic going that way?</em></p>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>ip route get</code> answers &ldquo;which way does this one address go?&rdquo;; <code>dig</code> answers &ldquo;what does DNS say?&rdquo;.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>ws1&rsquo;s view</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">netops@ws1:~$ ip -br addr
</span></span><span class="line"><span class="cl">lo               UNKNOWN        127.0.0.1/8
</span></span><span class="line"><span class="cl">tunl0@NONE       DOWN
</span></span><span class="line"><span class="cl">...
</span></span><span class="line"><span class="cl">eth0@if23        UP             172.80.102.11/24
</span></span><span class="line"><span class="cl">eth1@if28        UP             192.168.10.10/24
</span></span><span class="line"><span class="cl">netops@ws1:~$ ip route
</span></span><span class="line"><span class="cl">default via 192.168.10.1 dev eth1
</span></span><span class="line"><span class="cl">172.80.102.0/24 dev eth0 proto kernel scope link src 172.80.102.11
</span></span><span class="line"><span class="cl">192.168.10.0/24 dev eth1 proto kernel scope link src 192.168.10.10
</span></span></code></pre></div><p>The <code>tunl0</code>, <code>gre0</code> and other <code>DOWN</code> entries are spare tunnel interfaces that come from the computer the lab runs
inside. They have no address and nothing uses them. The numbers after <code>@if</code> will differ in yours.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Addresses, routes, names</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Log in, and list the interfaces and the routes:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh ws1
</span></span><span class="line"><span class="cl">ip -br addr
</span></span><span class="line"><span class="cl">ip route
</span></span></code></pre></div><p>The interface on <code>172.80.102.0/24</code> goes in <code>mgmt_interface</code>, and the address after <code>default via</code> in <code>gateway</code>.</p>
</li>
<li>
<p>Which DNS server does ws1 ask?</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat /etc/resolv.conf
</span></span></code></pre></div><p>The <code>nameserver</code> line is <code>dns_server</code>. <code>search lab</code> means a short name like <code>srv1</code> is tried as <code>srv1.lab</code>.</p>
</li>
<li>
<p>Ask it, the long way and the short way:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">dig srv1.lab
</span></span><span class="line"><span class="cl">dig +short srv1.lab
</span></span></code></pre></div><p>In the full answer, find the <strong>ANSWER SECTION</strong>, and at the bottom the <strong>SERVER</strong> line: who replied. The
address goes in <code>srv1_address</code>.</p>
</li>
<li>
<p><code>exit</code>, and fill in the four follow-along lines in <strong>answers/8.1.yml</strong>.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> resolv.conf names the DNS server; dig shows its whole answer, and +short just the address.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>The path to srv1</h2>
  </header>
  <div class="lab-stage-body">
    <p>From ws1:</p>
<ol>
<li>Which interface does ws1 send srv1&rsquo;s packets out of, <code>192.168.20.10</code>? Ask for that one address, not the whole
table. Write it in <code>route_dev</code>.</li>
<li>How many hops does <code>traceroute -n</code> count from ws1 to srv1? Write it in <code>hops_to_srv1</code>.</li>
</ol>
<p>Then <code>exit</code> and <code>make check T=8.1</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>ip route get 192.168.20.10</code>. The word after <code>dev</code> is the interface.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Each numbered line of traceroute&rsquo;s output is one hop, and the last is srv1 itself. If you see <code>* * *</code>, wait a few
seconds and run it again: Linux limits how fast it sends the ICMP replies traceroute depends on.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">netops@ws1:~$ ip route get 192.168.20.10
</span></span><span class="line"><span class="cl">192.168.20.10 via 192.168.10.1 dev eth1 src 192.168.10.10 uid 1000
</span></span><span class="line"><span class="cl">    cache
</span></span><span class="line"><span class="cl">netops@ws1:~$ traceroute -n srv1
</span></span><span class="line"><span class="cl">traceroute to srv1 (192.168.20.10), 30 hops max, 60 byte packets
</span></span><span class="line"><span class="cl"> 1  192.168.10.1  0.055 ms  9.405 ms  0.034 ms
</span></span><span class="line"><span class="cl"> 2  192.168.20.10  0.126 ms  3.454 ms  0.149 ms
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">hops_to_srv1</span><span class="p">:</span><span class="w"> </span><span class="m">2</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">route_dev</span><span class="p">:</span><span class="w"> </span><span class="l">eth1</span><span class="w">
</span></span></span></code></pre></div><p>No route says <em>192.168.20.0/24</em>, so ws1 uses its default: via r1 (<code>192.168.10.1</code>), out of <code>eth1</code>, from its own
<code>192.168.10.10</code>. Two hops: r1, then srv1.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Audit the configs</title><link>https://networkdoodles.com/labs/linux-cli-101/task-7-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-7-2/</guid><description> new to this? step by stepbeginner Read the header of scripts/audit.sh: it’s the spec. Check $1 is a folder ([ -d "$1" ]); if not, echo a usage line &gt;&amp;2 and exit 2. for f in "$1"/*.cfg; do ... done; skip it if [ -e "$f" ] fails; grep -q '^ntp server' "$f" or print basename "$f". chmod +x, try it on files/configs, then make check T=7.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li>Read the header of scripts/audit.sh: it&rsquo;s the spec.</li>
<li>Check <code>$1</code> is a folder (<code>[ -d &quot;$1&quot; ]</code>); if not, <code>echo</code> a usage line <code>&gt;&amp;2</code> and <code>exit 2</code>.</li>
<li><code>for f in &quot;$1&quot;/*.cfg; do ... done</code>; skip it if <code>[ -e &quot;$f&quot; ]</code> fails; <code>grep -q '^ntp server' &quot;$f&quot;</code> or print <code>basename &quot;$f&quot;</code>.</li>
<li><code>chmod +x</code>, try it on files/configs, then <code>make check T=7.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Loops over files, and the tests that guard them</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="for-loops-over-a-glob">for loops over a glob</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="k">for</span> f in files/configs/*.cfg<span class="p">;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="nb">echo</span> <span class="s2">&#34;checking </span><span class="nv">$f</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl"><span class="k">done</span>
</span></span></code></pre></div><p>The glob expands to every matching file, and the loop runs once for each, with <code>f</code> set to its path. Unlike
<code>$(ls ...)</code>, a glob keeps a name with a space as one name, as long as you write <code>&quot;$f&quot;</code> with quotes inside the loop.</p>
<p>When nothing matches, though, bash leaves the pattern as it is: in an empty folder, <code>f</code> is the text
<code>files/configs/*.cfg</code>, a file that doesn&rsquo;t exist. That&rsquo;s why loops like this start with a check.</p>
<h3 id="tests">Tests</h3>
<p><code>[ ... ]</code> is a command whose exit code answers a question, so it goes straight into an <code>if</code>:</p>
<table>
  <thead>
      <tr>
          <th>Test</th>
          <th>True when</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>[ -e &quot;$f&quot; ]</code></td>
          <td>f exists</td>
      </tr>
      <tr>
          <td><code>[ -d &quot;$f&quot; ]</code></td>
          <td>f is a folder</td>
      </tr>
      <tr>
          <td><code>[ -z &quot;$x&quot; ]</code></td>
          <td>x is empty</td>
      </tr>
      <tr>
          <td><code>! command</code></td>
          <td>turns a command&rsquo;s success into failure, and back</td>
      </tr>
  </tbody>
</table>
<h3 id="grep--q-an-answer-not-output">grep -q: an answer, not output</h3>
<p><code>grep -q PATTERN file</code> prints nothing at all; it exits 0 if it found a match and 1 if it didn&rsquo;t. <code>^</code> in the
pattern means <em>at the start of a line</em>, so <code>'^ntp server'</code> won&rsquo;t match a comment that mentions ntp.</p>
<h3 id="errors-go-to-stderr">Errors go to stderr</h3>
<p><code>echo &quot;usage: ...&quot; &gt;&amp;2</code> writes to stderr, stream 2, instead of stdout. A script that&rsquo;s used in a pipeline keeps
its real output on stdout and its complaints on stderr, so the two never mix.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> Loop over a glob with &ldquo;$f&rdquo; quoted, guard the empty case, test with [ ] and grep -q, complain on stderr.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>The practice folder</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ls files/configs
</span></span><span class="line"><span class="cl"> README.txt  &#39;chi leaf2.cfg&#39;   chi-leaf1.cfg   nyc-leaf1.cfg   nyc-leaf2.cfg
</span></span><span class="line"><span class="cl">$ grep -c &#39;^ntp server&#39; files/configs/*.cfg
</span></span><span class="line"><span class="cl">files/configs/chi leaf2.cfg:0
</span></span><span class="line"><span class="cl">files/configs/chi-leaf1.cfg:1
</span></span><span class="line"><span class="cl">files/configs/nyc-leaf1.cfg:1
</span></span><span class="line"><span class="cl">files/configs/nyc-leaf2.cfg:0
</span></span></code></pre></div><p><code>ls</code> quotes <code>'chi leaf2.cfg'</code> to show it&rsquo;s one name. The two with <code>0</code> are the ones your script should list.
Here&rsquo;s what goes wrong without quotes:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ for f in $(ls files/configs); do echo &#34;[$f]&#34;; done
</span></span><span class="line"><span class="cl">[README.txt]
</span></span><span class="line"><span class="cl">[chi]
</span></span><span class="line"><span class="cl">[leaf2.cfg]
</span></span><span class="line"><span class="cl">[chi-leaf1.cfg]
</span></span><span class="line"><span class="cl">...
</span></span></code></pre></div><p>One file has become two names, neither of which exists.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>The guard and the loop</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Run the starter, and look at what it says:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chmod +x scripts/audit.sh
</span></span><span class="line"><span class="cl">./scripts/audit.sh files/configs<span class="p">;</span> <span class="nb">echo</span> <span class="nv">$?</span>
</span></span></code></pre></div></li>
<li>
<p>Try the loop on its own in the terminal before you put it in the script:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="k">for</span> f in files/configs/*.cfg<span class="p">;</span> <span class="k">do</span> <span class="nb">echo</span> <span class="s2">&#34;[</span><span class="nv">$f</span><span class="s2">]&#34;</span><span class="p">;</span> <span class="k">done</span>
</span></span></code></pre></div><p>Four names, the spaced one in one piece.</p>
</li>
<li>
<p>And the test that the empty-folder case needs:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">mkdir -p /tmp/empty
</span></span><span class="line"><span class="cl"><span class="k">for</span> f in /tmp/empty/*.cfg<span class="p">;</span> <span class="k">do</span> <span class="nb">echo</span> <span class="s2">&#34;[</span><span class="nv">$f</span><span class="s2">]&#34;</span><span class="p">;</span> <span class="o">[</span> -e <span class="s2">&#34;</span><span class="nv">$f</span><span class="s2">&#34;</span> <span class="o">]</span> <span class="o">||</span> <span class="nb">echo</span> <span class="s2">&#34;  that one doesn&#39;t exist&#34;</span><span class="p">;</span> <span class="k">done</span>
</span></span></code></pre></div></li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> An unmatched glob stays as text, so check <code>[ -e &quot;$f&quot; ]</code> before using it.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Write audit.sh</h2>
  </header>
  <div class="lab-stage-body">
    <p>Replace the TODO in <strong>scripts/audit.sh</strong> with a script that does what its header says:</p>
<ul>
<li><code>./scripts/audit.sh DIR</code> prints the name (just the name, not the path) of every <code>.cfg</code> in DIR with no line
starting <code>ntp server</code>, one per line;</li>
<li>it exits <strong>1</strong> if it printed any, <strong>0</strong> if not, and an empty folder is fine;</li>
<li>with no DIR, or a DIR that isn&rsquo;t a folder, it prints a usage line on <strong>stderr</strong> and exits <strong>2</strong>.</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ./scripts/audit.sh files/configs; echo &#34;exit $?&#34;
</span></span><span class="line"><span class="cl">chi leaf2.cfg
</span></span><span class="line"><span class="cl">nyc-leaf2.cfg
</span></span><span class="line"><span class="cl">exit 1
</span></span></code></pre></div><p>Then <code>make check T=7.2</code>. It runs your script on folders it hasn&rsquo;t seen.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Do the guard first, at the top: <code>if [ -z &quot;$1&quot; ] || [ ! -d &quot;$1&quot; ]; then ... fi</code>. Run it with no argument to
check it, then move on.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Keep a <code>missing=0</code> before the loop, like <code>down=0</code> in reach.sh, and <code>exit &quot;$missing&quot;</code> at the end.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>basename &quot;$f&quot;</code> prints a path&rsquo;s last part: <code>files/configs/chi leaf2.cfg</code> becomes <code>chi leaf2.cfg</code>.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">dir</span><span class="o">=</span><span class="s2">&#34;</span><span class="si">${</span><span class="nv">1</span><span class="k">:-</span><span class="si">}</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl"><span class="k">if</span> <span class="o">[</span> -z <span class="s2">&#34;</span><span class="nv">$dir</span><span class="s2">&#34;</span> <span class="o">]</span> <span class="o">||</span> <span class="o">[</span> ! -d <span class="s2">&#34;</span><span class="nv">$dir</span><span class="s2">&#34;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
</span></span><span class="line"><span class="cl">  <span class="nb">echo</span> <span class="s2">&#34;usage: </span><span class="nv">$0</span><span class="s2"> DIR   (DIR is a folder of .cfg files)&#34;</span> &gt;<span class="p">&amp;</span><span class="m">2</span>
</span></span><span class="line"><span class="cl">  <span class="nb">exit</span> <span class="m">2</span>
</span></span><span class="line"><span class="cl"><span class="k">fi</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nv">missing</span><span class="o">=</span><span class="m">0</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> f in <span class="s2">&#34;</span><span class="nv">$dir</span><span class="s2">&#34;</span>/*.cfg<span class="p">;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="o">[</span> -e <span class="s2">&#34;</span><span class="nv">$f</span><span class="s2">&#34;</span> <span class="o">]</span> <span class="o">||</span> <span class="k">continue</span>                  <span class="c1"># an empty folder: the pattern matched nothing</span>
</span></span><span class="line"><span class="cl">  <span class="k">if</span> ! grep -q <span class="s1">&#39;^ntp server&#39;</span> <span class="s2">&#34;</span><span class="nv">$f</span><span class="s2">&#34;</span><span class="p">;</span> <span class="k">then</span>
</span></span><span class="line"><span class="cl">    basename <span class="s2">&#34;</span><span class="nv">$f</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="nv">missing</span><span class="o">=</span><span class="m">1</span>
</span></span><span class="line"><span class="cl">  <span class="k">fi</span>
</span></span><span class="line"><span class="cl"><span class="k">done</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">exit</span> <span class="s2">&#34;</span><span class="nv">$missing</span><span class="s2">&#34;</span>
</span></span></code></pre></div><p><code>${1:-}</code> is <code>$1</code>, or empty when there isn&rsquo;t one. This is about as far as a Bash script should go: once it needs
to parse configs properly, keep a list of results, or talk to devices, that&rsquo;s a job for Python
(<a href="/lessons/python-101/">Python 101</a>).</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Is everyone up?</title><link>https://networkdoodles.com/labs/linux-cli-101/task-7-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-7-1/</guid><description> new to this? step by stepbeginner chmod +x scripts/reach.sh, then ./scripts/reach.sh: it prints TODO lines. TODO 7.1a: an if ping -c 1 -W 1 "$host" &gt;/dev/null 2&gt;&amp;1; then ... else ... fi that prints $host up or $host down and sets down=1. TODO 7.1b: exit "$down" at the end. ./scripts/reach.sh; echo $? prints the four hosts, then 1. Then make check T=7.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>chmod +x scripts/reach.sh</code>, then <code>./scripts/reach.sh</code>: it prints TODO lines.</li>
<li>TODO 7.1a: an <code>if ping -c 1 -W 1 &quot;$host&quot; &gt;/dev/null 2&gt;&amp;1; then ... else ... fi</code> that prints <code>$host up</code> or <code>$host down</code> and sets <code>down=1</code>.</li>
<li>TODO 7.1b: <code>exit &quot;$down&quot;</code> at the end.</li>
<li><code>./scripts/reach.sh; echo $?</code> prints the four hosts, then 1. Then <code>make check T=7.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>A script is commands you&rsquo;d type</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="what-makes-a-file-a-script">What makes a file a script</h3>
<p>A <strong>script</strong> is a text file of commands, run one after another, as if you&rsquo;d typed them. Two things make it
runnable by name:</p>
<ul>
<li>its first line, the <strong>shebang</strong>, says which program reads it: <code>#!/usr/bin/env bash</code>;</li>
<li>it has <code>x</code> permission (<code>chmod +x</code>, chapter 4).</li>
</ul>
<p><code>./scripts/reach.sh</code> runs it; the <code>./</code> says <em>the one here</em>, because the lab&rsquo;s folder isn&rsquo;t on PATH.</p>
<h3 id="exit-codes">Exit codes</h3>
<p>Every command ends with an <strong>exit code</strong>, a number: <strong>0 means success</strong>, anything else means something went
wrong. The shell keeps the last one in <code>$?</code>. <code>if</code> runs a command and looks at its exit code, so <code>if ping ...</code>
means <em>if the ping worked</em>. A script&rsquo;s own exit code is what its <code>exit</code> says, which is how a script tells the
script that called it, or a CI pipeline, whether it worked.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> 0 is success; <code>if</code> tests a command&rsquo;s exit code, and <code>exit</code> sets your script&rsquo;s own.</p>
<h3 id="reading-a-file-line-by-line">Reading a file line by line</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="k">while</span> <span class="nb">read</span> -r host<span class="p">;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="nb">echo</span> <span class="s2">&#34;got </span><span class="nv">$host</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl"><span class="k">done</span> &lt; hosts.txt
</span></span></code></pre></div><p><code>read</code> takes one line from the file into the variable <code>host</code>, the loop body runs, and it repeats until the file
runs out. <code>&lt; hosts.txt</code> feeds the file into the whole loop. <code>-r</code> keeps backslashes as they are.</p>
<h3 id="quote-your-variables">Quote your variables</h3>
<p><code>&quot;$host&quot;</code>, not <code>$host</code>. Without quotes, the shell splits a value with spaces in it into separate words, and a
<code>*</code> in it turns into file names. With quotes, it stays one thing. Quote every <code>$</code> unless you have a reason not to.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>The starter</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">file</span><span class="o">=</span><span class="s2">&#34;</span><span class="si">${</span><span class="nv">1</span><span class="k">:-</span><span class="nv">hosts</span><span class="p">.txt</span><span class="si">}</span><span class="s2">&#34;</span>        <span class="c1"># the first argument, or hosts.txt if there isn&#39;t one</span>
</span></span><span class="line"><span class="cl"><span class="nv">down</span><span class="o">=</span><span class="m">0</span>                        <span class="c1"># becomes 1 as soon as one host doesn&#39;t answer</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">while</span> <span class="nb">read</span> -r host<span class="p">;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="k">case</span> <span class="s2">&#34;</span><span class="nv">$host</span><span class="s2">&#34;</span> in <span class="s2">&#34;&#34;</span><span class="p">|</span><span class="s2">&#34;#&#34;</span>*<span class="o">)</span> <span class="k">continue</span> <span class="p">;;</span> <span class="k">esac</span>      <span class="c1"># skip blank lines and comments</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="c1"># TODO 7.1a: ping &#34;$host&#34; once (-c 1), waiting at most one second (-W 1), and throw its output away.</span>
</span></span><span class="line"><span class="cl">  <span class="c1">#            If it answers, print &#34;$host up&#34;. If it doesn&#39;t, print &#34;$host down&#34; and set down=1.</span>
</span></span><span class="line"><span class="cl">  <span class="nb">echo</span> <span class="s2">&#34;TODO 7.1a is still open: </span><span class="nv">$host</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">done</span> &lt; <span class="s2">&#34;</span><span class="nv">$file</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># TODO 7.1b: finish with exit code $down, so that 0 means every host answered.</span>
</span></span></code></pre></div><p><code>$1</code> is the script&rsquo;s first argument, and <code>${1:-hosts.txt}</code> means <em><code>$1</code>, or <code>hosts.txt</code> if there isn&rsquo;t one</em>.
<code>case</code> skips blank lines and lines starting with <code>#</code>, and <code>continue</code> jumps straight to the next line.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Finish reach.sh</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Make it runnable, and run the starter:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chmod +x scripts/reach.sh
</span></span><span class="line"><span class="cl">./scripts/reach.sh
</span></span></code></pre></div><p>It reads hosts.txt and prints a TODO line for each host. The loop works; it just doesn&rsquo;t ping yet.</p>
</li>
<li>
<p>See what ping&rsquo;s exit code looks like for a host that answers and one that doesn&rsquo;t:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ping -c <span class="m">1</span> -W <span class="m">1</span> ws1 &gt;/dev/null 2&gt;<span class="p">&amp;</span>1<span class="p">;</span> <span class="nb">echo</span> <span class="nv">$?</span>
</span></span><span class="line"><span class="cl">ping -c <span class="m">1</span> -W <span class="m">1</span> 172.80.102.99 &gt;/dev/null 2&gt;<span class="p">&amp;</span>1<span class="p">;</span> <span class="nb">echo</span> <span class="nv">$?</span>
</span></span></code></pre></div><p><code>0</code>, then <code>1</code>. <code>&gt;/dev/null 2&gt;&amp;1</code> throws away both ping&rsquo;s output and its errors: you only want its exit code.</p>
</li>
<li>
<p>Open <strong>scripts/reach.sh</strong> and replace the <code>echo &quot;TODO 7.1a ...&quot;</code> line with:</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>scripts/reach.sh</code><span class="lab-file-how">Ctrl+P → reach.sh</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">  <span class="k">if</span> ping -c <span class="m">1</span> -W <span class="m">1</span> <span class="s2">&#34;</span><span class="nv">$host</span><span class="s2">&#34;</span> &gt;/dev/null 2&gt;<span class="p">&amp;</span>1<span class="p">;</span> <span class="k">then</span>
</span></span><span class="line"><span class="cl">    <span class="nb">echo</span> <span class="s2">&#34;</span><span class="nv">$host</span><span class="s2"> up&#34;</span>
</span></span><span class="line"><span class="cl">  <span class="k">else</span>
</span></span><span class="line"><span class="cl">    <span class="nb">echo</span> <span class="s2">&#34;</span><span class="nv">$host</span><span class="s2"> down&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="nv">down</span><span class="o">=</span><span class="m">1</span>
</span></span><span class="line"><span class="cl">  <span class="k">fi</span>
</span></span></code></pre></div></li>
<li>
<p>At the very end, under TODO 7.1b:</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>scripts/reach.sh</code><span class="lab-file-how">Ctrl+P → reach.sh</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">exit</span> <span class="s2">&#34;</span><span class="nv">$down</span><span class="s2">&#34;</span>
</span></span></code></pre></div></li>
<li>
<p>Run it, then ask for its exit code:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">./scripts/reach.sh
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="nv">$?</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">ws1 up
</span></span><span class="line"><span class="cl">srv1 up
</span></span><span class="line"><span class="cl">r1 up
</span></span><span class="line"><span class="cl">172.80.102.99 down
</span></span><span class="line"><span class="cl">1
</span></span></code></pre></div></li>
<li>
<p><code>make check T=7.1</code> runs it on hosts.txt and on two lists it hasn&rsquo;t seen.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>if command; then ...; else ...; fi</code> branches on an exit code; <code>exit</code> passes one on.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Use it the way scripts get used</h2>
  </header>
  <div class="lab-stage-body">
    <p>The script is done. Now use its exit code, the way a CI job or another script would:</p>
<ol>
<li>Make a list of only the hosts that answer, in a file of your own, and run <code>./scripts/reach.sh</code> on it. What&rsquo;s
<code>$?</code> now?</li>
<li>Run it so that it says <code>all up</code> only when every host answered, with <code>&amp;&amp;</code>. Try it on both lists.</li>
</ol>
<p>Nothing more to hand in: <code>make check T=7.1</code> is the check.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The script&rsquo;s first argument is the file: <code>./scripts/reach.sh mylist.txt</code>.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>a &amp;&amp; b</code> runs b only when a exited 0. <code>a || b</code> runs b only when a didn&rsquo;t.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">printf</span> <span class="s1">&#39;ws1\nsrv1\n&#39;</span> &gt; /tmp/up.txt
</span></span><span class="line"><span class="cl">./scripts/reach.sh /tmp/up.txt <span class="o">&amp;&amp;</span> <span class="nb">echo</span> <span class="s2">&#34;all up&#34;</span>
</span></span><span class="line"><span class="cl">./scripts/reach.sh <span class="o">||</span> <span class="nb">echo</span> <span class="s2">&#34;something is down&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">ws1 up
</span></span><span class="line"><span class="cl">srv1 up
</span></span><span class="line"><span class="cl">all up
</span></span></code></pre></div><p>That one exit code is what makes a script composable: a pipeline stage, a cron job or a pre-change check can all
stop on <code>1</code> without reading a word of the output.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Short names, a copy, a changed key</title><link>https://networkdoodles.com/labs/linux-cli-101/task-6-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-6-2/</guid><description> new to this? step by stepbeginner nano ~/.ssh/config: a Host block for each of ws1, srv1 (User netops) and r1 (User admin). ssh-copy-id srv1, then ssh srv1 and ssh ws1 work with no user name and no password. ssh r1 asks for r1’s password. scp files/notes/handover.txt srv1:, then ssh srv1 ls. make break T=6.2, then ssh srv1: read the warning. Remove srv1’s old key with ssh-keygen -R srv1, connect, check the new fingerprint, yes. make check T=6.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>nano ~/.ssh/config</code>: a <code>Host</code> block for each of ws1, srv1 (<code>User netops</code>) and r1 (<code>User admin</code>).</li>
<li><code>ssh-copy-id srv1</code>, then <code>ssh srv1</code> and <code>ssh ws1</code> work with no user name and no password. <code>ssh r1</code> asks for r1&rsquo;s password.</li>
<li><code>scp files/notes/handover.txt srv1:</code>, then <code>ssh srv1 ls</code>.</li>
<li><code>make break T=6.2</code>, then <code>ssh srv1</code>: read the warning. Remove srv1&rsquo;s old key with <code>ssh-keygen -R srv1</code>, connect, check the new fingerprint, <code>yes</code>.</li>
<li><code>make check T=6.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>ssh&rsquo;s own settings, and a key that changed</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="sshconfig">~/.ssh/config</h3>
<p>Typing <code>netops@</code> every time gets old, and real hosts have long names, odd ports and their own keys.
<code>~/.ssh/config</code> lets you give each host its settings once:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Host web
</span></span><span class="line"><span class="cl">    HostName srv1
</span></span><span class="line"><span class="cl">    User netops
</span></span><span class="line"><span class="cl">    Port 22
</span></span></code></pre></div><p><code>ssh web</code> now means <code>ssh -p 22 netops@srv1</code>. <code>Host</code> is the short name you type; <code>HostName</code> is the real name or
address (leave it out and the <code>Host</code> name is used). Everything that uses ssh reads this file: <code>scp</code>, Git,
Ansible.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> A Host block in ~/.ssh/config turns a short name into a user, a real host name and options.</p>
<h3 id="scp-copies-over-ssh">scp copies over SSH</h3>
<p><code>scp FROM TO</code> copies a file, and either end can be <code>host:path</code>. <code>scp notes.txt srv1:</code> copies <code>notes.txt</code> into
your home folder on srv1 (nothing after the colon means <em>home</em>); <code>scp srv1:notes.txt .</code> copies it back into the
folder you&rsquo;re in. Same logins, same keys, same <code>~/.ssh/config</code>.</p>
<h3 id="remote-host-identification-has-changed">&ldquo;Remote host identification has changed&rdquo;</h3>
<p>ssh remembers every host key you&rsquo;ve said yes to. If a host offers a <em>different</em> key next time, ssh refuses to
connect at all, and says so loudly. There are two reasons that can happen:</p>
<ul>
<li>the server was rebuilt or reinstalled, and made new host keys. Common, and harmless;</li>
<li>something between you and the server is pretending to be it: a <strong>man-in-the-middle</strong>. Rare, and the reason
ssh refuses instead of asking.</li>
</ul>
<p>You can&rsquo;t tell which from the warning alone. Find out (here, you know: you just rebuilt srv1), then remove the
old key, connect, and check the new fingerprint the way you did in task 6.1. Never turn the check off to make
the warning go away.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> A changed host key means a rebuilt server or an impostor: find out which, then replace the one old line.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>The warning</h2>
  </header>
  <div class="lab-stage-body">
    <p>After <code>make break T=6.2</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ssh srv1
</span></span><span class="line"><span class="cl">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
</span></span><span class="line"><span class="cl">@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
</span></span><span class="line"><span class="cl">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
</span></span><span class="line"><span class="cl">IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
</span></span><span class="line"><span class="cl">Someone could be eavesdropping on you right now (man-in-the-middle attack)!
</span></span><span class="line"><span class="cl">It is also possible that a host key has just been changed.
</span></span><span class="line"><span class="cl">The fingerprint for the ED25519 key sent by the remote host is
</span></span><span class="line"><span class="cl">SHA256:D5T0vLnK5aqJqyXkl0nNrxpCcACGUqPLTgSGR0KO4Eo.
</span></span><span class="line"><span class="cl">Please contact your system administrator.
</span></span><span class="line"><span class="cl">Add correct host key in /home/vscode/.ssh/known_hosts to get rid of this message.
</span></span><span class="line"><span class="cl">Offending ED25519 key in /home/vscode/.ssh/known_hosts:4
</span></span><span class="line"><span class="cl">  remove with:
</span></span><span class="line"><span class="cl">  ssh-keygen -f &#34;/home/vscode/.ssh/known_hosts&#34; -R &#34;srv1&#34;
</span></span><span class="line"><span class="cl">Host key for srv1 has changed and you have requested strict checking.
</span></span><span class="line"><span class="cl">Host key verification failed.
</span></span></code></pre></div><p>ssh tells you which line of <code>known_hosts</code> holds the old key, and the command that removes it. You can&rsquo;t just
read the file to find it: Debian <strong>hashes</strong> the names in <code>known_hosts</code>, so each line starts with <code>|1|</code> and a
scramble instead of <code>srv1</code>. <code>ssh-keygen -R</code> and <code>ssh-keygen -F</code> work by name anyway.</p>
<p>Your line number may differ. A server has more than one host key (ED25519, ECDSA, RSA), and after you log in
ssh saves all of them, so each machine you&rsquo;ve logged in to takes up three lines. <code>ssh-keygen -R srv1</code> removes
all of srv1&rsquo;s.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Short names</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Open ssh&rsquo;s config file. It doesn&rsquo;t exist yet, so nano makes it:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">nano ~/.ssh/config
</span></span></code></pre></div></li>
<li>
<p>Type a block for ws1, save (<kbd>Ctrl</kbd>+<kbd>O</kbd>, <kbd>Enter</kbd>) and leave
(<kbd>Ctrl</kbd>+<kbd>X</kbd>). The indentation is just for you; ssh doesn&rsquo;t mind it.</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>~/.ssh/config</code><span class="lab-file-how">Ctrl+P → config</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Host ws1
</span></span><span class="line"><span class="cl">    User netops
</span></span></code></pre></div></li>
<li>
<p>Try it: no user name, no password.</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh ws1 hostname
</span></span></code></pre></div></li>
<li>
<p>See every setting ssh would use for a host, from all its config files together, without connecting:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh -G ws1 <span class="p">|</span> head -n <span class="m">4</span>
</span></span></code></pre></div><p><code>user netops</code> is there.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> One Host block, and <code>ssh ws1</code> means <code>ssh netops@ws1</code>; <code>ssh -G</code> shows what ssh will really do.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Three names, one copy, one changed key</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>Add blocks for <strong>srv1</strong> (user <code>netops</code>) and <strong>r1</strong> (user <code>admin</code>) to <code>~/.ssh/config</code>. Put your key on srv1 too,
so <code>ssh srv1</code> needs no password. r1 is a router, so its login stays a password; <code>ssh r1</code> should just not need
the user name. (<code>exit</code> leaves r1.)</li>
<li>Copy <code>files/notes/handover.txt</code> into netops&rsquo;s home folder on srv1 with <code>scp</code>.</li>
<li><code>make break T=6.2</code> rebuilds srv1. <code>ssh srv1</code> now refuses. Make it work again: replace srv1&rsquo;s old host key,
checking the new fingerprint first (click <strong>srv1</strong> on the <strong>Topology</strong> tab, then the <code>ssh-keygen -lf</code> from task 6.1).</li>
</ol>
<p>Then <code>make check T=6.2</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>ssh-copy-id srv1</code> works with the short name as soon as srv1&rsquo;s block is in the config.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>scp FILE srv1:</code> copies into the home folder. <code>ssh srv1 cat handover.txt</code> checks it arrived.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The warning gives you the command. Then connect again: ssh asks about srv1&rsquo;s key as if it were the first time.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Host ws1
</span></span><span class="line"><span class="cl">    User netops
</span></span><span class="line"><span class="cl">Host srv1
</span></span><span class="line"><span class="cl">    User netops
</span></span><span class="line"><span class="cl">Host r1
</span></span><span class="line"><span class="cl">    User admin
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh-copy-id srv1
</span></span><span class="line"><span class="cl">scp files/notes/handover.txt srv1:
</span></span><span class="line"><span class="cl">ssh srv1 cat handover.txt
</span></span><span class="line"><span class="cl">make <span class="nb">break</span> <span class="nv">T</span><span class="o">=</span>6.2
</span></span><span class="line"><span class="cl">ssh srv1                       <span class="c1"># REMOTE HOST IDENTIFICATION HAS CHANGED</span>
</span></span><span class="line"><span class="cl">ssh-keygen -R srv1             <span class="c1"># removes srv1&#39;s old line from known_hosts</span>
</span></span><span class="line"><span class="cl">ssh srv1                       <span class="c1"># asks about the new key: check it, then yes</span>
</span></span></code></pre></div><p><code>make reset</code> puts srv1&rsquo;s original host key back, so after a reset you&rsquo;ll see this warning once more, for the
same harmless reason. Keys you&rsquo;ve put in <code>authorized_keys</code> go with a reset too: <code>ssh-copy-id</code> again.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Your first key</title><link>https://networkdoodles.com/labs/linux-cli-101/task-6-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-6-1/</guid><description> new to this? step by stepbeginner ssh-keygen -R ws1, then ssh netops@ws1. Compare the fingerprint it shows with ws1’s own (see given), then type yes, and the password netops-lab. exit. ssh-keygen -t ed25519: press Enter three times. ssh-copy-id netops@ws1: the password one last time. ssh netops@ws1: no password. exit. Fill in answers/6.1.yml, then make check T=6.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>ssh-keygen -R ws1</code>, then <code>ssh netops@ws1</code>. Compare the fingerprint it shows with ws1&rsquo;s own (see <em>given</em>), then type <code>yes</code>, and the password <code>netops-lab</code>. <code>exit</code>.</li>
<li><code>ssh-keygen -t ed25519</code>: press <kbd>Enter</kbd> three times.</li>
<li><code>ssh-copy-id netops@ws1</code>: the password one last time.</li>
<li><code>ssh netops@ws1</code>: no password. <code>exit</code>.</li>
<li>Fill in answers/6.1.yml, then <code>make check T=6.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Two kinds of key</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="ssh-checks-both-ends">SSH checks both ends</h3>
<p><strong>SSH</strong> (<em>Secure Shell</em>) gives you a command line on another machine, encrypted all the way. Every login proves
two things:</p>
<ol>
<li><strong>The server is who it says it is.</strong> Every SSH server has a <strong>host key</strong>. The first time you connect, ssh
shows you its <strong>fingerprint</strong>, a short summary of the key, and asks whether to trust it. If you say yes, it
remembers the key in <code>~/.ssh/known_hosts</code>, and checks it on every login after that.</li>
<li><strong>You are who you say you are.</strong> With a password, or with a key pair of your own.</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> The host key proves the server to you; a password or your own key proves you to the server.</p>
<h3 id="your-own-key-pair">Your own key pair</h3>
<p>A <strong>key pair</strong> is two files that belong together:</p>
<table>
  <thead>
      <tr>
          <th>File</th>
          <th>Who gets it</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>~/.ssh/id_ed25519</code></td>
          <td>the <strong>private key</strong>: it never leaves your machine, and only you can read it</td>
      </tr>
      <tr>
          <td><code>~/.ssh/id_ed25519.pub</code></td>
          <td>the <strong>public key</strong>: hand it to any server you want to log in to</td>
      </tr>
  </tbody>
</table>
<p>A server that has your public key in its <code>~/.ssh/authorized_keys</code> lets in whoever proves they hold the private
key, without the private key ever crossing the network. <code>ssh-copy-id</code> does the handing over: it logs in once
with your password and appends your public key to the server&rsquo;s <code>authorized_keys</code>.</p>
<p>This is how Ansible, Git and scripts log in to things: there&rsquo;s no one there to type a password.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> The private key stays with you; the public key goes into the server&rsquo;s authorized_keys.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>The first time you meet ws1</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ssh netops@ws1
</span></span><span class="line"><span class="cl">The authenticity of host &#39;ws1 (172.80.102.11)&#39; can&#39;t be established.
</span></span><span class="line"><span class="cl">ED25519 key fingerprint is SHA256:kjuhGNNG83Kh3Enr7x2BUZ+WvNjsbq0zOHZ8ZC5f9Xo.
</span></span><span class="line"><span class="cl">This key is not known by any other names.
</span></span><span class="line"><span class="cl">Are you sure you want to continue connecting (yes/no/[fingerprint])?
</span></span></code></pre></div><p>Your fingerprint is different: every lab builds its own ws1. ssh can&rsquo;t know whether this is really ws1 or
something pretending to be it; only you can, by checking the fingerprint against one you got another way. On
a real network that&rsquo;s the server&rsquo;s admin, or its console. Here, ask ws1 itself, without SSH: on the lab app&rsquo;s
<strong>Topology</strong> tab, click <strong>ws1</strong>. That opens a root shell on it, in a tab of its own, like sitting at its console:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">root@ws1:~# ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
</span></span><span class="line"><span class="cl">256 SHA256:kjuhGNNG83Kh3Enr7x2BUZ+WvNjsbq0zOHZ8ZC5f9Xo root@buildkitsandbox (ED25519)
</span></span></code></pre></div><p>The same fingerprint: it&rsquo;s safe to say yes. (<code>buildkitsandbox</code> is just a label from when the image was
built.)</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Password, then key</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Check ws1&rsquo;s fingerprint from the inside first: on the <strong>Topology</strong> tab, click <strong>ws1</strong>, and in the <strong>ws1</strong> tab:</p>
<div class="lab-file lab-file-tab mono">
  <span class="lab-file-kind">run in the ws1 tab</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
</span></span></code></pre></div><p>Keep that tab open, and go back to the <strong>VS Code</strong> tab&rsquo;s terminal for the rest.</p>
</li>
<li>
<p>You said <code>yes</code> to ws1&rsquo;s key in task 4.2, so ssh remembers it and won&rsquo;t ask again. Make it forget, so you
meet ws1 the way you&rsquo;d meet a new server, then connect. Compare the fingerprint ssh shows with the one above.
Same? Type <code>yes</code>, then the password <code>netops-lab</code> (nothing appears while you type it; that&rsquo;s normal):</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh-keygen -R ws1
</span></span><span class="line"><span class="cl">ssh netops@ws1
</span></span></code></pre></div><p><code>ssh-keygen -R ws1</code> prints <em># Host ws1 found</em> and keeps the old file as <code>known_hosts.old</code>. If it finds
nothing, that&rsquo;s fine too: you skipped 4.2&rsquo;s login.</p>
<p>The prompt becomes <code>netops@ws1:~$</code>. Copy the fingerprint, starting <code>SHA256:</code>, into <code>ws1_fingerprint</code>.
Then <code>exit</code>.</p>
</li>
<li>
<p>Make your key pair. <code>-t ed25519</code> picks the key type; the codespace&rsquo;s ssh is older and would make an RSA key
without it. Press <kbd>Enter</kbd> at each question to take the default file and no passphrase:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh-keygen -t ed25519
</span></span><span class="line"><span class="cl">ls -l ~/.ssh
</span></span></code></pre></div><p><code>id_ed25519</code> is <code>-rw-------</code>, private; <code>id_ed25519.pub</code> is <code>-rw-r--r--</code>.</p>
</li>
<li>
<p>Hand the public key to ws1. It asks for the password one last time:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh-copy-id netops@ws1
</span></span></code></pre></div></li>
<li>
<p>Log in again:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh netops@ws1
</span></span><span class="line"><span class="cl">cat ~/.ssh/authorized_keys
</span></span><span class="line"><span class="cl"><span class="nb">exit</span>
</span></span></code></pre></div><p>No password. And there, on ws1, is your public key, the same line as <code>cat ~/.ssh/id_ed25519.pub</code> in the
codespace.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> ssh-keygen makes the pair, ssh-copy-id installs the public half, and the password is never needed again.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Run something without logging in</h2>
  </header>
  <div class="lab-stage-body">
    <p>Nothing more for the checker in this one: the follow-along is the task. But try what a key makes possible.
ssh runs one command and comes straight back when you put it after the host:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh netops@ws1 hostname
</span></span><span class="line"><span class="cl">ssh netops@ws1 <span class="s1">&#39;uptime; df -h /&#39;</span>
</span></span></code></pre></div><p>This is exactly what Ansible does for every task on every host. Then run <code>make check T=6.1</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Asked for a password again? <code>ssh-copy-id</code> didn&rsquo;t finish. Run it again, then check <code>~/.ssh/authorized_keys</code> on ws1.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Don&rsquo;t make a passphrase-less key for a real account without thinking about it: anyone who copies the file is
you. The lesson covers passphrases and ssh-agent.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ssh netops@ws1 hostname
</span></span><span class="line"><span class="cl">ws1
</span></span></code></pre></div><p>The quotes in the second command matter: without them, your own shell would see the <code>;</code> and run <code>df -h /</code> in
the codespace instead.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Runaway</title><link>https://networkdoodles.com/labs/linux-cli-101/task-5-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-5-2/</guid><description> new to this? step by stepbeginner make break T=5.2, then top: the busy process is at the top. Note its PID. kill &lt;PID&gt;, check with ps -p &lt;PID&gt;. Still there? A signal it can’t ignore. mkdir -p ~/tools, cp files/labinfo ~/tools/, chmod +x ~/tools/labinfo. Add export PATH="$HOME/tools:$PATH" to ~/.bashrc; in a new terminal, labinfo works from anywhere. Fill in answers/5.2.yml, then make check T=5.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>make break T=5.2</code>, then <code>top</code>: the busy process is at the top. Note its PID.</li>
<li><code>kill &lt;PID&gt;</code>, check with <code>ps -p &lt;PID&gt;</code>. Still there? A signal it can&rsquo;t ignore.</li>
<li><code>mkdir -p ~/tools</code>, <code>cp files/labinfo ~/tools/</code>, <code>chmod +x ~/tools/labinfo</code>.</li>
<li>Add <code>export PATH=&quot;$HOME/tools:$PATH&quot;</code> to <code>~/.bashrc</code>; in a new terminal, <code>labinfo</code> works from anywhere.</li>
<li>Fill in answers/5.2.yml, then <code>make check T=5.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Signals, and how the shell finds a command</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="kill-sends-a-signal">kill sends a signal</h3>
<p><code>kill</code> doesn&rsquo;t kill. It sends a <strong>signal</strong>, a short message, and the process decides what to do with it:</p>
<table>
  <thead>
      <tr>
          <th>Signal</th>
          <th>Number</th>
          <th>Means</th>
          <th>Can the process ignore it?</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>TERM</code></td>
          <td>15</td>
          <td>please stop: tidy up and exit. What <code>kill</code> sends by default</td>
          <td>yes</td>
      </tr>
      <tr>
          <td><code>INT</code></td>
          <td>2</td>
          <td>interrupted: what <kbd>Ctrl</kbd>+<kbd>C</kbd> sends</td>
          <td>yes</td>
      </tr>
      <tr>
          <td><code>HUP</code></td>
          <td>1</td>
          <td>the terminal hung up; many servers read it as <em>reload your config</em></td>
          <td>yes</td>
      </tr>
      <tr>
          <td><code>KILL</code></td>
          <td>9</td>
          <td>stop now. The kernel ends it without asking</td>
          <td><strong>no</strong></td>
      </tr>
  </tbody>
</table>
<p>Try <code>TERM</code> first: a program that gets it can save its work. <code>KILL</code> (<code>kill -9</code>) is for the ones that won&rsquo;t
listen.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> kill sends TERM, which a process may ignore; KILL can&rsquo;t be ignored, so save it for last.</p>
<h3 id="path">PATH</h3>
<p>When you type <code>ls</code>, the shell doesn&rsquo;t search the whole disk. It looks through a list of folders, in order, and
runs the first <code>ls</code> it finds. That list is the environment variable <strong><code>PATH</code></strong>, with a <code>:</code> between folders.
<code>which ls</code> says which one it found.</p>
<p>To make a command of your own runnable from anywhere, put it in a folder and put that folder on <code>PATH</code>. Put
your folder <em>first</em> (<code>$HOME/tools:$PATH</code>) and your command wins over any other with the same name.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> PATH is the list of folders the shell searches for commands, first match wins.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>PATH, one folder per line</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ echo $PATH | tr : &#39;\n&#39;
</span></span><span class="line"><span class="cl">/home/vscode/.venvs/lab/bin
</span></span><span class="line"><span class="cl">/home/vscode/.local/bin
</span></span><span class="line"><span class="cl">/home/vscode/.atuin/bin
</span></span><span class="line"><span class="cl">/usr/local/python/current/bin
</span></span><span class="line"><span class="cl">...
</span></span><span class="line"><span class="cl">/usr/local/bin
</span></span><span class="line"><span class="cl">/usr/sbin
</span></span><span class="line"><span class="cl">/usr/bin
</span></span><span class="line"><span class="cl">/sbin
</span></span><span class="line"><span class="cl">/bin
</span></span></code></pre></div><p><code>tr : '\n'</code> swaps each <code>:</code> for a new line, so the list is readable. The first folder is the lab&rsquo;s Python
<strong>venv</strong>, which is why <code>which python</code> in task 5.1 found that python and not the system&rsquo;s. Python 101 explains
venvs.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Make a command of your own</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Try the script where it is:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat files/labinfo
</span></span><span class="line"><span class="cl">files/labinfo
</span></span></code></pre></div><p><em>Permission denied</em>: task 4.2&rsquo;s problem.</p>
</li>
<li>
<p>Give it a home, and make it runnable:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">mkdir -p ~/tools
</span></span><span class="line"><span class="cl">cp files/labinfo ~/tools/
</span></span><span class="line"><span class="cl">chmod +x ~/tools/labinfo
</span></span><span class="line"><span class="cl">~/tools/labinfo
</span></span></code></pre></div></li>
<li>
<p>From another folder, by name alone, it isn&rsquo;t found yet:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> /
</span></span><span class="line"><span class="cl">labinfo
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> -
</span></span></code></pre></div><p><code>bash: labinfo: command not found</code>: <code>~/tools</code> isn&rsquo;t on PATH.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> A command runs by name only if its folder is on PATH, and only if it has x.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Stop the runaway, then fix PATH</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li><code>make break T=5.2</code> starts a program called <strong>labhog</strong> that keeps one CPU at 100%. Find its PID (that&rsquo;s
<code>hog_pid</code>) and stop it. The polite way first, then, when that doesn&rsquo;t work, the way that can&rsquo;t be ignored.
The signal that worked goes in <code>signal_that_worked</code>.</li>
<li>Make every new terminal find <code>labinfo</code> from any folder.</li>
</ol>
<p>Then <code>make check T=5.2</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>top</code> puts the busiest process first, with its PID in the first column. <code>ps -eo pid,pcpu,comm --sort=-pcpu | head</code> says the same thing in one go.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>After a <code>kill</code>, <code>ps -p &lt;PID&gt;</code> shows whether it&rsquo;s still there. labhog ignores TERM, INT and HUP.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>PATH is set the same way as <code>LAB_SITE</code> in task 5.1: one <code>export</code> line at the end of <code>~/.bashrc</code>, with your
folder in front of the old PATH.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ps -eo pid,pcpu,comm --sort<span class="o">=</span>-pcpu <span class="p">|</span> head -n <span class="m">3</span>     <span class="c1"># labhog, at the top</span>
</span></span><span class="line"><span class="cl"><span class="nb">kill</span> <span class="m">41234</span>                                        <span class="c1"># its PID: yours is different</span>
</span></span><span class="line"><span class="cl">ps -p <span class="m">41234</span>                                       <span class="c1"># still running: it ignores TERM</span>
</span></span><span class="line"><span class="cl"><span class="nb">kill</span> -9 <span class="m">41234</span>
</span></span><span class="line"><span class="cl">ps -p <span class="m">41234</span>                                       <span class="c1"># gone</span>
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;export PATH=&#34;$HOME/tools:$PATH&#34;&#39;</span> &gt;&gt; ~/.bashrc
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">hog_pid</span><span class="p">:</span><span class="w"> </span><span class="m">41234</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">signal_that_worked</span><span class="p">:</span><span class="w"> </span><span class="l">KILL</span><span class="w">
</span></span></span></code></pre></div><p>Open a new terminal and <code>cd /; labinfo</code>. The double quotes in the <code>export</code> line matter: they keep the
whole PATH as one value, even if a folder in it ever has a space in its name.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Jobs and variables</title><link>https://networkdoodles.com/labs/linux-cli-101/task-5-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-5-1/</guid><description> new to this? step by stepbeginner sleep 300 &amp;, jobs, fg, Ctrl+Z, jobs again, bg, kill %1. ps, then top (q quits). echo $0, which python. Challenge: LAB_SITE=nyc, bash -c 'echo $LAB_SITE' (empty), export LAB_SITE, again (nyc). Then put export LAB_SITE=nyc in ~/.bashrc and open a new terminal. Fill in answers/5.1.yml, then make check T=5.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>sleep 300 &amp;</code>, <code>jobs</code>, <code>fg</code>, <kbd>Ctrl</kbd>+<kbd>Z</kbd>, <code>jobs</code> again, <code>bg</code>, <code>kill %1</code>.</li>
<li><code>ps</code>, then <code>top</code> (<kbd>q</kbd> quits). <code>echo $0</code>, <code>which python</code>.</li>
<li>Challenge: <code>LAB_SITE=nyc</code>, <code>bash -c 'echo $LAB_SITE'</code> (empty), <code>export LAB_SITE</code>, again (nyc). Then put
<code>export LAB_SITE=nyc</code> in <code>~/.bashrc</code> and open a new terminal.</li>
<li>Fill in answers/5.1.yml, then <code>make check T=5.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Programs that run, and what they&rsquo;re told</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="processes-and-jobs">Processes and jobs</h3>
<p>A <strong>process</strong> is a program that&rsquo;s running. Each has a number, its <strong>PID</strong> (<em>process ID</em>), and a parent: the
process that started it. Everything you type in the terminal is started by the shell, so the shell is its
parent.</p>
<p>A command normally runs in the <strong>foreground</strong>: the shell waits for it to finish before it gives you the
prompt back. End a command with <code>&amp;</code> and it runs in the <strong>background</strong>, and the shell asks for the next one
straight away. The shell calls the commands it&rsquo;s keeping track of <strong>jobs</strong>:</p>
<table>
  <thead>
      <tr>
          <th>You type</th>
          <th>Does</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>cmd &amp;</code></td>
          <td>start cmd in the background</td>
      </tr>
      <tr>
          <td><code>jobs</code></td>
          <td>list this terminal&rsquo;s jobs, with their numbers</td>
      </tr>
      <tr>
          <td><code>fg</code></td>
          <td>bring the newest job to the foreground (<code>fg %2</code> for job 2)</td>
      </tr>
      <tr>
          <td><kbd>Ctrl</kbd>+<kbd>Z</kbd></td>
          <td>pause the job in the foreground</td>
      </tr>
      <tr>
          <td><code>bg</code></td>
          <td>let a paused job carry on, in the background</td>
      </tr>
      <tr>
          <td><kbd>Ctrl</kbd>+<kbd>C</kbd></td>
          <td>stop the job in the foreground</td>
      </tr>
      <tr>
          <td><code>kill %1</code></td>
          <td>stop job 1 (<code>kill 1234</code> stops PID 1234)</td>
      </tr>
  </tbody>
</table>
<p><code>ps</code> lists processes; <code>top</code> shows them live, the busiest first.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> A process has a PID; <code>&amp;</code> runs it in the background, and jobs, fg and bg move it around.</p>
<h3 id="environment-variables">Environment variables</h3>
<p>Every process carries a set of <strong>environment variables</strong>: names with values, like <code>HOME=/home/vscode</code> and
<code>USER=vscode</code>, that programs read to know where they are and how to behave. <code>echo $HOME</code> prints one.</p>
<p>A variable you set in the shell, <code>LAB_SITE=nyc</code>, belongs to that shell only. <strong><code>export</code></strong> marks it to be handed
down to every program the shell starts from then on. And nothing you set lasts beyond the terminal it was set
in: a new terminal starts from scratch and runs <strong><code>~/.bashrc</code></strong>, so that&rsquo;s where settings you always want go.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>export</code> hands a variable down to the programs a shell starts; ~/.bashrc sets it in every new terminal.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>A job, paused and resumed</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sleep 300 &amp;
</span></span><span class="line"><span class="cl">[1] 10638
</span></span><span class="line"><span class="cl">$ jobs
</span></span><span class="line"><span class="cl">[1]+  Running                 sleep 300 &amp;
</span></span><span class="line"><span class="cl">$ ps
</span></span><span class="line"><span class="cl">  PID TTY          TIME CMD
</span></span><span class="line"><span class="cl">10608 pts/0    00:00:00 bash
</span></span><span class="line"><span class="cl">10638 pts/0    00:00:00 sleep
</span></span><span class="line"><span class="cl">10660 pts/0    00:00:00 ps
</span></span></code></pre></div><p><code>[1]</code> is the job number and <code>10638</code> its PID; yours will differ. <code>sleep 300</code> does nothing for 300 seconds,
which makes it a good process to practise on. <code>ps</code> with no options lists only this terminal&rsquo;s processes: the
shell, the sleep, and <code>ps</code> itself.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Jobs, then the shell&rsquo;s own facts</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Start a job in the background, and list it:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sleep <span class="m">300</span> <span class="p">&amp;</span>
</span></span><span class="line"><span class="cl"><span class="nb">jobs</span>
</span></span><span class="line"><span class="cl">ps
</span></span></code></pre></div></li>
<li>
<p>Bring it to the foreground. The prompt doesn&rsquo;t come back: the shell is waiting for it.</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">fg</span>
</span></span></code></pre></div></li>
<li>
<p>Press <kbd>Ctrl</kbd>+<kbd>Z</kbd>. The prompt comes back and the job is paused. Ask about it:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">jobs</span>
</span></span></code></pre></div><p>The one word <code>jobs</code> uses for its state goes in <code>stopped_word</code>.</p>
</li>
<li>
<p>Let it carry on in the background, then stop it for good:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">bg</span>
</span></span><span class="line"><span class="cl"><span class="nb">kill</span> %1
</span></span><span class="line"><span class="cl"><span class="nb">jobs</span>
</span></span></code></pre></div></li>
<li>
<p>Every process on the machine, live, the busiest at the top. Watch it for a few seconds, then find the key
that quits (it&rsquo;s in <code>top</code>&rsquo;s help: press <kbd>h</kbd>). That key goes in <code>top_quit_key</code>.</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">top
</span></span></code></pre></div></li>
<li>
<p>Two facts about your shell:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="nv">$0</span>
</span></span><span class="line"><span class="cl">which python
</span></span></code></pre></div><p><code>$0</code> is the name of the program you&rsquo;re typing into: that&rsquo;s <code>shell_name</code>. <code>which</code> says where a command lives;
copy its answer into <code>python_path</code>. Chapter 5.2 explains why it&rsquo;s that one.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> Ctrl+Z pauses, bg resumes in the background, fg brings it back; top shows every process live.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>A variable that sticks</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>Set <code>LAB_SITE</code> to <code>nyc</code> in your terminal, and check that <code>echo $LAB_SITE</code> prints it.</li>
<li>Now ask a <em>child</em> process, a second bash started by this one, what it sees:
<code>bash -c 'echo $LAB_SITE'</code>. Make the child see it too.</li>
<li>Open a new terminal (the <strong>+</strong> in the terminal panel): <code>LAB_SITE</code> is gone. Make every new terminal start with
it, exported.</li>
</ol>
<p>Then run <code>make check T=5.1</code>. It opens a fresh bash of its own, the way a new terminal would.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The single quotes in <code>bash -c 'echo $LAB_SITE'</code> stop <em>your</em> shell from filling in <code>$LAB_SITE</code>, so the child
does it. That&rsquo;s the point.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>~/.bashrc</code> is a file of commands that every new terminal runs first. Add one line to the end of it. <code>&gt;&gt;</code>
appends; one <code>&gt;</code> would replace the whole file, so be careful.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">LAB_SITE</span><span class="o">=</span>nyc
</span></span><span class="line"><span class="cl">bash -c <span class="s1">&#39;echo $LAB_SITE&#39;</span>        <span class="c1"># prints an empty line: not exported</span>
</span></span><span class="line"><span class="cl"><span class="nb">export</span> LAB_SITE
</span></span><span class="line"><span class="cl">bash -c <span class="s1">&#39;echo $LAB_SITE&#39;</span>        <span class="c1"># nyc</span>
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;export LAB_SITE=nyc&#39;</span> &gt;&gt; ~/.bashrc
</span></span><span class="line"><span class="cl">tail -n <span class="m">1</span> ~/.bashrc
</span></span></code></pre></div><p>Or open <code>~/.bashrc</code> in nano and add the line at the end. The change only applies to terminals opened after it;
<code>source ~/.bashrc</code> applies it to the one you&rsquo;re in.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Too open, too closed</title><link>https://networkdoodles.com/labs/linux-cli-101/task-4-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-4-2/</guid><description> new to this? step by stepbeginner make break T=4.2, then ls -l work work/keys work/bin. ssh -i work/keys/lab_key netops@ws1: read the warning. Type yes if it asks about ws1’s key first. work/bin/hello.sh: Permission denied. Fix each with chmod, try again, fill in answers/4.2.yml, then make check T=4.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>make break T=4.2</code>, then <code>ls -l work work/keys work/bin</code>.</li>
<li><code>ssh -i work/keys/lab_key netops@ws1</code>: read the warning. Type <code>yes</code> if it asks about ws1&rsquo;s key first.</li>
<li><code>work/bin/hello.sh</code>: Permission denied.</li>
<li>Fix each with <code>chmod</code>, try again, fill in answers/4.2.yml, then <code>make check T=4.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Permissions that are wrong both ways</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="too-open">Too open</h3>
<p>Some programs refuse to work when a file is readable by people who shouldn&rsquo;t read it. <code>ssh</code> is the strict
one: a <strong>private key</strong>, the file that proves who you are (chapter 6), must be readable by you alone. If the group
or everyone else can read it, ssh won&rsquo;t use it, because anyone else on the machine could copy it.</p>
<h3 id="too-closed">Too closed</h3>
<p>The opposite mistake: a script without <code>x</code> can&rsquo;t be run as a program, however correct the code in it is. The
shell says <em>Permission denied</em>, which sounds like you aren&rsquo;t allowed. You are; the file just isn&rsquo;t marked as a
program.</p>
<h3 id="writable-by-everyone">Writable by everyone</h3>
<p>A file with <code>w</code> for <em>other</em> can be changed by every user on the machine. <code>ls -l</code> shows it as a <code>w</code> in the
last set, like <code>-rw-rw-rw-</code>. It rarely breaks anything straight away, which is why it&rsquo;s easy to miss.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> Keys must be private, programs need x, and nothing shared should be writable by everyone.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>What make break leaves</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ls -l work/keys work/bin work/team-notes.txt
</span></span><span class="line"><span class="cl">-rw-rw-rw- 1 vscode vscode   64 Nov 11 05:52 work/team-notes.txt
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">work/bin:
</span></span><span class="line"><span class="cl">total 4
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode 47 Nov 11 05:52 hello.sh
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">work/keys:
</span></span><span class="line"><span class="cl">total 8
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode 399 Nov 11 05:52 lab_key
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode  89 Nov 11 05:52 lab_key.pub
</span></span></code></pre></div><p><code>lab_key.pub</code> is the <em>public</em> half of the key pair; anyone may read that one. <code>lab_key</code> is the private half.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Meet the three errors</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Set the task up, and look at what it made:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">make <span class="nb">break</span> <span class="nv">T</span><span class="o">=</span>4.2
</span></span><span class="line"><span class="cl">ls -l work/keys work/bin work/team-notes.txt
</span></span></code></pre></div></li>
<li>
<p>Try the key. If ssh first asks <em>Are you sure you want to continue connecting?</em>, type <code>yes</code>: that&rsquo;s ws1
introducing itself, and chapter 6 is all about it.</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ssh -i work/keys/lab_key netops@ws1
</span></span></code></pre></div><p>A box of <code>@</code> signs, a warning in capitals, <em>bad permissions</em>, and then a password prompt: ssh ignored the
key. Press <kbd>Ctrl</kbd>+<kbd>C</kbd>. The capitalised word that starts the warning goes in <code>ssh_warning</code>.</p>
</li>
<li>
<p>Try the script:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">work/bin/hello.sh
</span></span></code></pre></div></li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> ssh says a key is too open; the shell says a script without x is Permission denied.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Fix all three</h2>
  </header>
  <div class="lab-stage-body">
    <p>Change only the permissions, not the files&rsquo; owner or contents:</p>
<ol>
<li><code>work/keys/lab_key</code>: only you can read it. Then <code>ssh -i work/keys/lab_key netops@ws1</code> logs in without a
password. <code>exit</code> comes back.</li>
<li><code>work/bin/hello.sh</code>: it runs, and only you can change it.</li>
<li><code>work/team-notes.txt</code>: everyone can read it, only you can change it.</li>
</ol>
<p>Fill in <code>ssh_warning</code> and run <code>make check T=4.2</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Each of the three is one row of the table of numbers in task 4.1.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>ls -l</code> after each <code>chmod</code>, to see that it did what you meant.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chmod <span class="m">600</span> work/keys/lab_key
</span></span><span class="line"><span class="cl">chmod <span class="m">755</span> work/bin/hello.sh
</span></span><span class="line"><span class="cl">chmod <span class="m">644</span> work/team-notes.txt
</span></span><span class="line"><span class="cl">ssh -i work/keys/lab_key netops@ws1 hostname
</span></span><span class="line"><span class="cl">work/bin/hello.sh
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">ssh_warning</span><span class="p">:</span><span class="w"> </span><span class="l">UNPROTECTED</span><span class="w">
</span></span></span></code></pre></div><p>ssh&rsquo;s warning is <em>UNPROTECTED PRIVATE KEY FILE!</em>, and it names the permissions it found: <code>0644</code>. <code>400</code> works
for the key too (read-only, even for you), and <code>700</code> works for the script. The checker accepts anything that&rsquo;s
private for the key, and runnable, but not writable by others, for the script.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Who may do what</title><link>https://networkdoodles.com/labs/linux-cli-101/task-4-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-4-1/</guid><description> new to this? step by stepbeginner ls -l /etc/shadow: its owner, group and permissions. cat /etc/shadow, then sudo head -n 1 /etc/shadow. mkdir -p work, touch work/private.txt, chmod 600 work/private.txt. Write work/run.sh (echo 'echo "it runs"' &gt; work/run.sh), chmod 755 work/run.sh, run work/run.sh. Challenge: traceroute is missing. sudo apt update, then sudo apt install traceroute. Fill in answers/4.1.yml, then make check T=4.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>ls -l /etc/shadow</code>: its owner, group and permissions. <code>cat /etc/shadow</code>, then <code>sudo head -n 1 /etc/shadow</code>.</li>
<li><code>mkdir -p work</code>, <code>touch work/private.txt</code>, <code>chmod 600 work/private.txt</code>.</li>
<li>Write <code>work/run.sh</code> (<code>echo 'echo &quot;it runs&quot;' &gt; work/run.sh</code>), <code>chmod 755 work/run.sh</code>, run <code>work/run.sh</code>.</li>
<li>Challenge: <code>traceroute</code> is missing. <code>sudo apt update</code>, then <code>sudo apt install traceroute</code>.</li>
<li>Fill in answers/4.1.yml, then <code>make check T=4.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Owner, group, everyone else</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="reading-ls--l">Reading ls -l</h3>
<p>Each line of <code>ls -l</code> starts with ten characters: the type, then three sets of three permissions.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">-rw-r----- 1 root shadow 543 Nov  7 10:44 /etc/shadow
</span></span><span class="line"><span class="cl">│└┬┘└┬┘└┬┘   └┬─┘ └─┬──┘
</span></span><span class="line"><span class="cl">│ │  │  │     │     └── the file&#39;s group
</span></span><span class="line"><span class="cl">│ │  │  │     └──────── its owner
</span></span><span class="line"><span class="cl">│ │  │  └────────────── everyone else (other): ---  nothing
</span></span><span class="line"><span class="cl">│ │  └───────────────── the group:             r--  read
</span></span><span class="line"><span class="cl">│ └──────────────────── the owner:             rw-  read and write
</span></span><span class="line"><span class="cl">└────────────────────── the type: - a file, d a folder
</span></span></code></pre></div><table>
  <thead>
      <tr>
          <th>Letter</th>
          <th>On a file</th>
          <th>On a folder</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>r</code> read</td>
          <td>read it</td>
          <td>list what&rsquo;s in it</td>
      </tr>
      <tr>
          <td><code>w</code> write</td>
          <td>change it</td>
          <td>add, rename and delete files in it</td>
      </tr>
      <tr>
          <td><code>x</code> execute</td>
          <td>run it as a program</td>
          <td>go into it (<code>cd</code>)</td>
      </tr>
  </tbody>
</table>
<p class="lab-recap"><span class="mono">in one sentence</span> Three sets of rwx: the owner&rsquo;s, the group&rsquo;s, and everyone else&rsquo;s.</p>
<h3 id="the-numbers">The numbers</h3>
<p>Each set is also written as one digit, adding <strong>r = 4</strong>, <strong>w = 2</strong> and <strong>x = 1</strong>. So <code>rw-</code> is 6, <code>r-x</code> is 5,
<code>rwx</code> is 7 and <code>---</code> is 0. Three digits cover the three sets:</p>
<table>
  <thead>
      <tr>
          <th>Number</th>
          <th>Letters</th>
          <th>Typical for</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>600</code></td>
          <td><code>rw-------</code></td>
          <td>private files: SSH keys, passwords</td>
      </tr>
      <tr>
          <td><code>644</code></td>
          <td><code>rw-r--r--</code></td>
          <td>ordinary files: anyone may read, only you may change</td>
      </tr>
      <tr>
          <td><code>755</code></td>
          <td><code>rwxr-xr-x</code></td>
          <td>programs and folders: anyone may run or enter, only you may change</td>
      </tr>
      <tr>
          <td><code>700</code></td>
          <td><code>rwx------</code></td>
          <td>private folders, like <code>~/.ssh</code></td>
      </tr>
  </tbody>
</table>
<p><code>chmod 600 file</code> sets them by number; <code>chmod +x file</code> and <code>chmod o-w file</code> add or take away one letter.</p>
<h3 id="root-and-sudo">root and sudo</h3>
<p><strong>root</strong> is the user that permissions don&rsquo;t stop. You aren&rsquo;t root, and that&rsquo;s on purpose: a mistake as root can
break the whole machine. <code>sudo command</code> runs one command as root, when you&rsquo;re allowed to. On a server it
asks for <em>your</em> password and logs what you ran; in this codespace it doesn&rsquo;t ask.</p>
<p>Installing software changes folders only root may write to, so <code>apt</code>, Debian&rsquo;s package manager, needs <code>sudo</code>.
<code>apt update</code> refreshes the list of what can be installed; <code>apt install name</code> installs it.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>sudo</code> runs one command as root; installing with apt is one of the things that needs it.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>A file you can&rsquo;t read</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ls -l /etc/shadow
</span></span><span class="line"><span class="cl">-rw-r----- 1 root shadow 543 Nov  7 10:44 /etc/shadow
</span></span><span class="line"><span class="cl">$ cat /etc/shadow
</span></span><span class="line"><span class="cl">cat: /etc/shadow: Permission denied
</span></span><span class="line"><span class="cl">$ id
</span></span><span class="line"><span class="cl">uid=1000(vscode) gid=1000(vscode) groups=1000(vscode),104(docker),997(clab_admins),998(pipx),999(nvm),1001(ssh)
</span></span></code></pre></div><p><code>/etc/shadow</code> holds the users&rsquo; password hashes. You&rsquo;re <code>vscode</code>, not root and not in the <code>shadow</code> group, so
you fall under <em>other</em>, and <em>other</em> has <code>---</code>. <code>id</code> lists who you are and every group you&rsquo;re in.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Read, then set, permissions</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Look at the file and try to read it:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ls -l /etc/shadow
</span></span><span class="line"><span class="cl">cat /etc/shadow
</span></span></code></pre></div><p>The owner, the group, and the last words of cat&rsquo;s message go in <code>shadow_owner</code>, <code>shadow_group</code> and
<code>without_sudo</code>.</p>
</li>
<li>
<p>Now as root, just its first line:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo head -n <span class="m">1</span> /etc/shadow
</span></span></code></pre></div><p>It works. The long string after <code>root:</code> is a hash, or <code>*</code> if the account has no password.</p>
</li>
<li>
<p>Make yourself a folder to work in, and a private file in it. <code>touch</code> makes an empty file:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">mkdir -p work
</span></span><span class="line"><span class="cl">touch work/private.txt
</span></span><span class="line"><span class="cl">ls -l work
</span></span><span class="line"><span class="cl">chmod <span class="m">600</span> work/private.txt
</span></span><span class="line"><span class="cl">ls -l work
</span></span></code></pre></div><p>Watch the <code>-rw-r--r--</code> turn into <code>-rw-------</code>.</p>
</li>
<li>
<p>A tiny program, then try to run it before and after <code>chmod</code>:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;echo &#34;it runs&#34;&#39;</span> &gt; work/run.sh
</span></span><span class="line"><span class="cl">work/run.sh
</span></span><span class="line"><span class="cl">chmod <span class="m">755</span> work/run.sh
</span></span><span class="line"><span class="cl">work/run.sh
</span></span></code></pre></div><p>The first try says <em>Permission denied</em>: no <code>x</code>, no running.</p>
</li>
<li>
<p>Fill in the three answers:</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>answers/4.1.yml</code><span class="lab-file-how">Ctrl+P → 4.1.yml</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">shadow_owner</span><span class="p">:</span><span class="w"> </span><span class="l">root</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">shadow_group</span><span class="p">:</span><span class="w"> </span><span class="l">shadow</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">without_sudo</span><span class="p">:</span><span class="w"> </span><span class="l">Permission denied</span><span class="w">
</span></span></span></code></pre></div></li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>chmod 600</code> is private, <code>chmod 755</code> is a program anyone can run; <code>sudo</code> does one thing as root.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Install what&rsquo;s missing</h2>
  </header>
  <div class="lab-stage-body">
    <p>Chapter 8 uses <code>traceroute</code>, and the codespace doesn&rsquo;t have it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ traceroute
</span></span><span class="line"><span class="cl">bash: traceroute: command not found
</span></span></code></pre></div><p>Install it with apt. Then <code>traceroute --version</code> to prove it&rsquo;s there, and run <code>make check T=4.1</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Without <code>sudo</code>, apt can&rsquo;t write where software lives. Read the error it prints: it says so.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>A fresh codespace has an empty package list, so apt says <em>Unable to locate package</em>. <code>sudo apt update</code> fetches
the list first.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo apt update
</span></span><span class="line"><span class="cl">sudo apt install traceroute
</span></span><span class="line"><span class="cl">traceroute --version
</span></span></code></pre></div><p>apt asks <em>Do you want to continue?</em> only when it needs to install other packages too; traceroute has none
to add here, so it just installs. <code>-y</code> answers yes for you, which scripts use. The program lands in
<code>/usr/sbin/traceroute</code>, a folder only root may write to, which is the whole reason for <code>sudo</code>.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Who's knocking?</title><link>https://networkdoodles.com/labs/linux-cli-101/task-3-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-3-2/</guid><description> new to this? step by stepbeginner LOG=files/logs/r1.log, then grep LOGIN_FAILED "$LOG". Which field is the user name? Count them, count them per name with cut, sort, uniq -c and sort -rn, and list the names with sort -u. Put each command in answers/3.2.yml, then make check T=3.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>LOG=files/logs/r1.log</code>, then <code>grep LOGIN_FAILED &quot;$LOG&quot;</code>. Which field is the user name?</li>
<li>Count them, count them per name with <code>cut</code>, <code>sort</code>, <code>uniq -c</code> and <code>sort -rn</code>, and list the names with <code>sort -u</code>.</li>
<li>Put each command in answers/3.2.yml, then <code>make check T=3.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>A log is evidence</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="why-failed-logins-matter">Why failed logins matter</h3>
<p>Every router and server on the internet sees logins it didn&rsquo;t expect: someone, or more often a script, trying
common user names and passwords. One failure is a typo. Thirty for <code>admin</code> in a minute is a scan. A pipeline
turns a page of log lines into the two questions that matter: how many, and who.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> Counting failures per user name tells a typo from a scan in one line.</p>
<h3 id="three-tools-you-havent-used-yet">Three tools you haven&rsquo;t used yet</h3>
<table>
  <thead>
      <tr>
          <th>Tool</th>
          <th>Does</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>sort -u</code></td>
          <td>sorts and keeps each line once (<em>unique</em>): the same as <code>sort | uniq</code></td>
      </tr>
      <tr>
          <td><code>head -n 3</code></td>
          <td>after a sort, keeps the top 3</td>
      </tr>
      <tr>
          <td><code>wc -l</code></td>
          <td>counts lines; <code>grep -c</code> does the same for matching lines, in one step</td>
      </tr>
  </tbody>
</table>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>The lines to work from</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ grep LOGIN_FAILED &#34;$LOG&#34; | head -n 3
</span></span><span class="line"><span class="cl">*Nov 11 05:42:38.832: %CAPEOS-4-LOGIN_FAILED: Login failed for guest from 172.80.102.1 port 41694
</span></span><span class="line"><span class="cl">*Nov 11 05:42:47.185: %CAPEOS-4-LOGIN_FAILED: Login failed for netops from 172.80.102.1 port 41698
</span></span><span class="line"><span class="cl">*Nov 11 05:43:01.375: %CAPEOS-4-LOGIN_FAILED: Login failed for netops from 172.80.102.1 port 33882
</span></span></code></pre></div><p>These are real: the lab tried to log in to r1 with names r1 doesn&rsquo;t know. Every attempt came from
<code>172.80.102.1</code>, the codespace&rsquo;s address on the management network.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Find the field</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Set <code>LOG</code> again if this is a new terminal, and look at the failures:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">LOG</span><span class="o">=</span>files/logs/r1.log
</span></span><span class="line"><span class="cl">grep LOGIN_FAILED <span class="s2">&#34;</span><span class="nv">$LOG</span><span class="s2">&#34;</span>
</span></span></code></pre></div></li>
<li>
<p>Count the words in one of those lines, the way <code>cut -d' '</code> will. Which field is the user name? Try your
guess:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">grep LOGIN_FAILED <span class="s2">&#34;</span><span class="nv">$LOG</span><span class="s2">&#34;</span> <span class="p">|</span> cut -d<span class="s1">&#39; &#39;</span> -f8
</span></span></code></pre></div><p>If that printed <code>failed</code> or <code>from</code>, count again: <code>*Nov</code> is field 1.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> Find the field once, by counting, then let cut pull it out of every line.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>How many, and who</h2>
  </header>
  <div class="lab-stage-body">
    <p>Three commands in <strong>answers/3.2.yml</strong>, each reading <code>&quot;$LOG&quot;</code>:</p>
<ol>
<li><code>failed_total</code>: how many failed logins there are, as one number.</li>
<li><code>failed_by_user</code>: failed logins per user name, biggest count first, like <code>      3 netops</code>.</li>
<li><code>users_once</code>: every user name that failed, once each, from A to Z, one per line.</li>
</ol>
<p>Then <code>make check T=3.2</code>. The checker&rsquo;s other logs have names r1.log doesn&rsquo;t, so nothing can be typed in by hand.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The first is one grep with an option you used in task 3.1.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The second is task 3.1&rsquo;s <code>downs_per_interface</code> again, on different lines and a different field.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The third needs no counting at all: cut out the names, then <code>sort -u</code>.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">failed_total</span><span class="p">:</span><span class="w"> </span><span class="l">grep -c LOGIN_FAILED &#34;$LOG&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">failed_by_user</span><span class="p">:</span><span class="w"> </span><span class="l">grep LOGIN_FAILED &#34;$LOG&#34; | cut -d&#39; &#39; -f8 | sort | uniq -c | sort -rn</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">users_once</span><span class="p">:</span><span class="w"> </span><span class="l">grep LOGIN_FAILED &#34;$LOG&#34; | cut -d&#39; &#39; -f8 | sort -u</span><span class="w">
</span></span></span></code></pre></div><p>On r1.log:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">      3 netops
</span></span><span class="line"><span class="cl">      2 support
</span></span><span class="line"><span class="cl">      2 guest
</span></span><span class="line"><span class="cl">      1 operator
</span></span></code></pre></div><p><code>netops</code> exists on ws1 and srv1, but not on r1, so to r1 it&rsquo;s a stranger. <code>support</code> and <code>guest</code> have the same
count, so either can come first.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Pipelines</title><link>https://networkdoodles.com/labs/linux-cli-101/task-3-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-3-1/</guid><description> new to this? step by stepbeginner LOG=files/logs/r1.log, then try each command with "$LOG" where the file name goes. grep -c GigabitEthernet2 "$LOG", grep LOGIN_FAILED "$LOG", grep -vc CONFIG_DONE "$LOG". Challenge: grep LINK_DOWN "$LOG" | cut -d' ' -f6 | sort | uniq -c | sort -rn, and a grep with &gt; reports/errors.txt. Put each command on its line in answers/3.1.yml, then make check T=3.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>LOG=files/logs/r1.log</code>, then try each command with <code>&quot;$LOG&quot;</code> where the file name goes.</li>
<li><code>grep -c GigabitEthernet2 &quot;$LOG&quot;</code>, <code>grep LOGIN_FAILED &quot;$LOG&quot;</code>, <code>grep -vc CONFIG_DONE &quot;$LOG&quot;</code>.</li>
<li>Challenge: <code>grep LINK_DOWN &quot;$LOG&quot; | cut -d' ' -f6 | sort | uniq -c | sort -rn</code>, and a <code>grep</code> with <code>&gt; reports/errors.txt</code>.</li>
<li>Put each command on its line in answers/3.1.yml, then <code>make check T=3.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Small tools, joined up</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="every-program-has-three-streams">Every program has three streams</h3>
<p>When a program runs, it gets three <strong>streams</strong>, numbered:</p>
<table>
  <thead>
      <tr>
          <th>#</th>
          <th>Name</th>
          <th>Normally</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>0</td>
          <td><strong>stdin</strong>, standard input</td>
          <td>what you type</td>
      </tr>
      <tr>
          <td>1</td>
          <td><strong>stdout</strong>, standard output</td>
          <td>the screen</td>
      </tr>
      <tr>
          <td>2</td>
          <td><strong>stderr</strong>, standard error</td>
          <td>the screen too, kept apart for error messages</td>
      </tr>
  </tbody>
</table>
<p>The shell can point each one somewhere else:</p>
<table>
  <thead>
      <tr>
          <th>You type</th>
          <th>Means</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>cmd &gt; file</code></td>
          <td>stdout into <em>file</em>, replacing what was in it</td>
      </tr>
      <tr>
          <td><code>cmd &gt;&gt; file</code></td>
          <td>stdout onto the end of <em>file</em></td>
      </tr>
      <tr>
          <td><code>cmd 2&gt; file</code></td>
          <td>stderr into <em>file</em> (<code>2&gt;/dev/null</code> throws errors away)</td>
      </tr>
      <tr>
          <td><code>cmd1 | cmd2</code></td>
          <td>a <strong>pipe</strong>: cmd1&rsquo;s stdout becomes cmd2&rsquo;s stdin</td>
      </tr>
  </tbody>
</table>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>&gt;</code> sends output to a file, <code>|</code> sends it into the next command, and errors travel separately on stderr.</p>
<h3 id="the-tools-that-go-in-a-pipeline">The tools that go in a pipeline</h3>
<table>
  <thead>
      <tr>
          <th>Tool</th>
          <th>Does</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>grep WORD</code></td>
          <td>keeps the lines that contain WORD. <code>-c</code> counts them, <code>-v</code> keeps the ones that don&rsquo;t, <code>-i</code> ignores case</td>
      </tr>
      <tr>
          <td><code>cut -d' ' -f6</code></td>
          <td>keeps the 6th field of each line, splitting on spaces (<code>-d</code> is the <em>delimiter</em>)</td>
      </tr>
      <tr>
          <td><code>sort</code></td>
          <td>sorts lines. <code>-n</code> by number, <code>-r</code> reversed</td>
      </tr>
      <tr>
          <td><code>uniq -c</code></td>
          <td>squashes repeated <em>neighboring</em> lines into one, with a count in front. That&rsquo;s why it comes after <code>sort</code></td>
      </tr>
      <tr>
          <td><code>wc -l</code></td>
          <td>counts lines</td>
      </tr>
  </tbody>
</table>
<h3 id="why-the-commands-say-log">Why the commands say &ldquo;$LOG&rdquo;</h3>
<p><code>LOG=files/logs/r1.log</code> sets a shell <strong>variable</strong> called <code>LOG</code>, and <code>&quot;$LOG&quot;</code> is replaced with its value. The
checker sets <code>LOG</code> to other log files and runs your command again on each, so a command that only works on
r1.log, or that types the answer in, won&rsquo;t pass. Chapter 5 explains variables properly.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>One question, one line</h2>
  </header>
  <div class="lab-stage-body">
    <p>The <code>LINK_DOWN</code> lines, then the same lines cut down to field 6, the interface:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ grep LINK_DOWN &#34;$LOG&#34;
</span></span><span class="line"><span class="cl">*Nov 11 05:42:33.264: %CAPEOS-3-LINK_DOWN: Interface GigabitEthernet2 is down (administratively)
</span></span><span class="line"><span class="cl">*Nov 11 05:42:55.209: %CAPEOS-3-LINK_DOWN: Interface GigabitEthernet1 is down (administratively)
</span></span><span class="line"><span class="cl">*Nov 11 05:43:19.370: %CAPEOS-3-LINK_DOWN: Interface GigabitEthernet2 is down (administratively)
</span></span><span class="line"><span class="cl">*Nov 11 05:43:49.571: %CAPEOS-3-LINK_DOWN: Interface GigabitEthernet2 is down (administratively)
</span></span><span class="line"><span class="cl">$ grep LINK_DOWN &#34;$LOG&#34; | cut -d&#39; &#39; -f6
</span></span><span class="line"><span class="cl">GigabitEthernet2
</span></span><span class="line"><span class="cl">GigabitEthernet1
</span></span><span class="line"><span class="cl">GigabitEthernet2
</span></span><span class="line"><span class="cl">GigabitEthernet2
</span></span></code></pre></div><p>Counting fields: <code>*Nov</code> is 1, <code>11</code> is 2, the time is 3, <code>%CAPEOS-3-LINK_DOWN:</code> is 4, <code>Interface</code> is 5, and the
interface is 6. And an error, on stderr, then the same with stderr thrown away:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ cat nope.txt
</span></span><span class="line"><span class="cl">cat: nope.txt: No such file or directory
</span></span><span class="line"><span class="cl">$ cat nope.txt 2&gt;/dev/null
</span></span><span class="line"><span class="cl">$
</span></span></code></pre></div>
  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Three questions</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Point <code>LOG</code> at the practice log. Type it exactly, with no spaces around the <code>=</code>:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">LOG</span><span class="o">=</span>files/logs/r1.log
</span></span></code></pre></div></li>
<li>
<p>How many lines mention GigabitEthernet2?</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">grep -c GigabitEthernet2 <span class="s2">&#34;</span><span class="nv">$LOG</span><span class="s2">&#34;</span>
</span></span></code></pre></div></li>
<li>
<p>Only the failed logins:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">grep LOGIN_FAILED <span class="s2">&#34;</span><span class="nv">$LOG</span><span class="s2">&#34;</span>
</span></span></code></pre></div></li>
<li>
<p>How many lines are <em>not</em> CONFIG_DONE? <code>-v</code> turns grep inside out, and <code>-c</code> counts what&rsquo;s left:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">grep -vc CONFIG_DONE <span class="s2">&#34;</span><span class="nv">$LOG</span><span class="s2">&#34;</span>
</span></span></code></pre></div></li>
<li>
<p>Copy each command into <strong>answers/3.1.yml</strong>, on the line after its question. Leave <code>&quot;$LOG&quot;</code> as it is:</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>answers/3.1.yml</code><span class="lab-file-how">Ctrl+P → 3.1.yml</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">gi2_lines</span><span class="p">:</span><span class="w"> </span><span class="l">grep -c GigabitEthernet2 &#34;$LOG&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">failed_lines</span><span class="p">:</span><span class="w"> </span><span class="l">grep LOGIN_FAILED &#34;$LOG&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">not_config</span><span class="p">:</span><span class="w"> </span><span class="l">grep -vc CONFIG_DONE &#34;$LOG&#34;</span><span class="w">
</span></span></span></code></pre></div></li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>grep</code> keeps matching lines, <code>-c</code> counts them, <code>-v</code> keeps the others.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Per interface, and into a file</h2>
  </header>
  <div class="lab-stage-body">
    <p>Two more lines in <strong>answers/3.1.yml</strong>:</p>
<ol>
<li>
<p><code>downs_per_interface</code>: for each interface, how many times it went down (<code>LINK_DOWN</code>), biggest count first,
one line each, the way <code>uniq -c</code> prints it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">      3 GigabitEthernet2
</span></span><span class="line"><span class="cl">      1 GigabitEthernet1
</span></span></code></pre></div></li>
<li>
<p><code>save_errors</code>: every severity 3 line (they have <code>-3-</code> in them) into <code>reports/errors.txt</code>, with nothing on
the screen.</p>
</li>
</ol>
<p>Build each one a step at a time in the terminal, adding one <code>|</code> and one tool, and look at the output before
you add the next. Then run <code>make check T=3.1</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The first starts from the show stage: <code>grep LINK_DOWN &quot;$LOG&quot; | cut -d' ' -f6</code>. What&rsquo;s left is counting the
same lines, and putting the biggest first.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>uniq -c</code> only counts lines that are next to each other, so <code>sort</code> first. Then <code>sort -rn</code> sorts the counts as
numbers, biggest first.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>To grep for something that starts with <code>-</code>, tell grep the options are over with <code>--</code>: <code>grep -- -3- &quot;$LOG&quot;</code>.
Otherwise it thinks <code>-3-</code> is an option.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">downs_per_interface</span><span class="p">:</span><span class="w"> </span><span class="l">grep LINK_DOWN &#34;$LOG&#34; | cut -d&#39; &#39; -f6 | sort | uniq -c | sort -rn</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">save_errors</span><span class="p">:</span><span class="w"> </span><span class="l">grep -- -3- &#34;$LOG&#34; &gt; reports/errors.txt</span><span class="w">
</span></span></span></code></pre></div><p><code>cat reports/errors.txt</code> shows the eight severity 3 lines: every LINK_DOWN and LINK_UP. Without the first
<code>sort</code>, <code>uniq -c</code> counts runs instead of totals; without <code>sort -rn</code> at the end, the interfaces come out in
alphabetical order. Both pass on r1.log by luck sometimes, which is why the checker tries other logs.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Tidy up</title><link>https://networkdoodles.com/labs/linux-cli-101/task-2-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-2-2/</guid><description> new to this? step by stepbeginner find files -name '*.cfg' -empty lists the empty configs; find files -name '*leaf2*' the leaf2 files. Count them. Challenge: in files/backups, mkdir r1 sw1, mv the file with the space to a name with a dash, delete the empty configs, then mv r1-*.cfg r1/ and the same for sw1. ls -R files/backups should show r1/ and sw1/ with two configs each, and README.txt. Fill in answers/2.2.yml, then make check T=2.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>find files -name '*.cfg' -empty</code> lists the empty configs; <code>find files -name '*leaf2*'</code> the leaf2 files. Count them.</li>
<li>Challenge: in files/backups, <code>mkdir r1 sw1</code>, <code>mv</code> the file with the space to a name with a dash, delete the
empty configs, then <code>mv r1-*.cfg r1/</code> and the same for sw1.</li>
<li><code>ls -R files/backups</code> should show r1/ and sw1/ with two configs each, and README.txt.</li>
<li>Fill in answers/2.2.yml, then <code>make check T=2.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Moving files without a mouse</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="copy-move-delete">Copy, move, delete</h3>
<table>
  <thead>
      <tr>
          <th>Command</th>
          <th>Does</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>mkdir r1</code></td>
          <td>makes a folder (<code>mkdir -p a/b/c</code> makes the whole chain)</td>
      </tr>
      <tr>
          <td><code>cp a b</code></td>
          <td>copies a to b</td>
      </tr>
      <tr>
          <td><code>mv a b</code></td>
          <td>moves a to b. If b is in the same folder, that&rsquo;s a <strong>rename</strong></td>
      </tr>
      <tr>
          <td><code>mv a b c dir/</code></td>
          <td>moves several files into a folder</td>
      </tr>
      <tr>
          <td><code>rm a</code></td>
          <td>deletes a file. <strong>There&rsquo;s no recycle bin</strong>: it&rsquo;s gone</td>
      </tr>
      <tr>
          <td><code>rmdir dir</code></td>
          <td>deletes an empty folder</td>
      </tr>
  </tbody>
</table>
<p class="lab-recap"><span class="mono">in one sentence</span> mv both moves and renames; rm deletes for good, with no bin to fish it out of.</p>
<h3 id="globs-one-pattern-many-files">Globs: one pattern, many files</h3>
<p>A <strong>glob</strong> is a pattern the shell turns into a list of matching file names <em>before</em> the command runs:</p>
<table>
  <thead>
      <tr>
          <th>Pattern</th>
          <th>Matches</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>*</code></td>
          <td>any characters, any number of them (also none)</td>
      </tr>
      <tr>
          <td><code>?</code></td>
          <td>exactly one character</td>
      </tr>
      <tr>
          <td><code>r1-*.cfg</code></td>
          <td>every name that starts <code>r1-</code> and ends <code>.cfg</code></td>
      </tr>
  </tbody>
</table>
<p>So <code>mv r1-*.cfg r1/</code> is really <code>mv r1-2026-11-01.cfg r1-2026-11-02.cfg r1/</code>: <code>mv</code> never sees the <code>*</code>. Try
<code>echo r1-*.cfg</code> first to see what a glob turns into; <code>echo</code> just prints it.</p>
<h3 id="names-with-spaces">Names with spaces</h3>
<p>The shell splits a command line on spaces, so <code>mv sw1 2026-11-02.cfg new.cfg</code> means <em>three</em> things to move.
Quote a name with spaces in it: <code>'sw1 2026-11-02.cfg'</code>. <kbd>Tab</kbd> adds the quoting for you.</p>
<h3 id="find-search-the-tree">find: search the tree</h3>
<p><code>find</code> walks a folder and everything under it, and prints each path that matches all its tests:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">find files -name &#39;*.cfg&#39;            every .cfg file under files/
</span></span><span class="line"><span class="cl">find files -name &#39;*.cfg&#39; -empty     ... that&#39;s empty
</span></span><span class="line"><span class="cl">find files -type d                  every folder
</span></span></code></pre></div><p>Quote the pattern after <code>-name</code>, so the shell hands the <code>*</code> to find instead of expanding it first.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> Globs are expanded by the shell; find searches a whole tree; quote anything with a space or a * you want to keep.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>The mess</h2>
  </header>
  <div class="lab-stage-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ls -l files/backups
</span></span><span class="line"><span class="cl">total 20
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode  83 Nov 11 05:51 README.txt
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode 304 Nov 11 05:51 r1-2026-11-01.cfg
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode 398 Nov 11 05:51 r1-2026-11-02.cfg
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode   0 Nov 11 05:51 r1-2026-11-03.cfg
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode 277 Nov 11 05:51 sw1 2026-11-02.cfg
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode 304 Nov 11 05:51 sw1-2026-11-01.cfg
</span></span><span class="line"><span class="cl">-rw-r--r-- 1 vscode vscode   0 Nov 11 05:51 sw1-2026-11-03.cfg
</span></span></code></pre></div><p>The fifth column is each file&rsquo;s size in bytes. Two of them are <code>0</code>: someone&rsquo;s save failed. One name has a space
where the others have a dash.</p>
<p>When it&rsquo;s tidy, it should look like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ls -R files/backups
</span></span><span class="line"><span class="cl">files/backups:
</span></span><span class="line"><span class="cl">README.txt  r1  sw1
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">files/backups/r1:
</span></span><span class="line"><span class="cl">r1-2026-11-01.cfg  r1-2026-11-02.cfg
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">files/backups/sw1:
</span></span><span class="line"><span class="cl">sw1-2026-11-01.cfg  sw1-2026-11-02.cfg
</span></span></code></pre></div>
  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Count with find</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Every config under <code>files/</code>:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">find files -name <span class="s1">&#39;*.cfg&#39;</span>
</span></span></code></pre></div></li>
<li>
<p>Just the empty ones. How many? That&rsquo;s <code>empty_files</code>:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">find files -name <span class="s1">&#39;*.cfg&#39;</span> -empty
</span></span></code></pre></div></li>
<li>
<p>Every file with <code>leaf2</code> anywhere in its name. Count the lines: that&rsquo;s <code>leaf2_files</code>. Look closely at the
one in <code>files/configs</code>.</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">find files -name <span class="s1">&#39;*leaf2*&#39;</span>
</span></span></code></pre></div></li>
<li>
<p>See what a glob turns into before you trust it with <code>mv</code>:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> files/backups
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> r1-*.cfg
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> sw1-*.cfg
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> -
</span></span></code></pre></div><p>Notice that <code>sw1-*.cfg</code> doesn&rsquo;t match the file with the space: there&rsquo;s no dash in its name.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>find PATH -name 'PATTERN'</code> searches a whole tree; <code>echo</code> a glob to see what it will match.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Tidy the backups</h2>
  </header>
  <div class="lab-stage-body">
    <p>Write your two counts in <strong>answers/2.2.yml</strong> first: once you delete the empty files, <code>find</code> can&rsquo;t find them.</p>
<p>Then make <code>files/backups</code> look like the tidy listing above:</p>
<ul>
<li>a folder for each device, <code>r1</code> and <code>sw1</code>, with that device&rsquo;s configs in it;</li>
<li><code>sw1 2026-11-02.cfg</code> renamed to <code>sw1-2026-11-02.cfg</code>, like the others;</li>
<li>the empty configs deleted;</li>
<li><code>README.txt</code> left where it is.</li>
</ul>
<p>Don&rsquo;t edit the configs themselves: the checker compares each one with the file it started as. Then run
<code>make check T=2.2</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>cd files/backups</code> first, so every name is short. <code>mkdir r1 sw1</code> makes both folders at once.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Rename the odd one before you move anything: <code>mv 'sw1 2026-11-02.cfg' sw1-2026-11-02.cfg</code>. Then <code>sw1-*.cfg</code>
matches it too.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>find . -maxdepth 1 -name '*.cfg' -empty -delete</code> deletes the empty ones in this folder (<code>-maxdepth 1</code>: don&rsquo;t
look in the subfolders). Or <code>rm</code> them by name: there are only two.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">empty_files</span><span class="p">:</span><span class="w"> </span><span class="m">2</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">leaf2_files</span><span class="p">:</span><span class="w"> </span><span class="m">4</span><span class="w">
</span></span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> files/backups
</span></span><span class="line"><span class="cl">mkdir r1 sw1
</span></span><span class="line"><span class="cl">mv <span class="s1">&#39;sw1 2026-11-02.cfg&#39;</span> sw1-2026-11-02.cfg
</span></span><span class="line"><span class="cl">rm r1-2026-11-03.cfg sw1-2026-11-03.cfg
</span></span><span class="line"><span class="cl">mv r1-*.cfg r1/
</span></span><span class="line"><span class="cl">mv sw1-*.cfg sw1/
</span></span><span class="line"><span class="cl">ls -R
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> -
</span></span></code></pre></div><p>The order matters: delete the empty files before the globs move them, and rename the spaced one before
<code>sw1-*.cfg</code> runs, or it&rsquo;s left behind. <code>files/configs/chi leaf2.cfg</code> is the fourth leaf2 file, the one <code>ls</code>
shows as two words.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Read and write</title><link>https://networkdoodles.com/labs/linux-cli-101/task-2-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-2-1/</guid><description> new to this? step by stepbeginner head -n 1 files/logs/r1.log and tail -n 1 files/logs/r1.log: the first and last events. less files/logs/r1.log, type /GigabitEthernet1 and Enter, n for the next match, q to quit. make live, then tail -f files/logs/live.log. Note the word. Ctrl+C stops watching. Challenge: nano ~/notes.txt, type checked r1, Ctrl+O Enter to save, Ctrl+X to leave. Fill in answers/2.1.yml, then make check T=2.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>head -n 1 files/logs/r1.log</code> and <code>tail -n 1 files/logs/r1.log</code>: the first and last events.</li>
<li><code>less files/logs/r1.log</code>, type <code>/GigabitEthernet1</code> and <kbd>Enter</kbd>, <kbd>n</kbd> for the next match, <kbd>q</kbd> to quit.</li>
<li><code>make live</code>, then <code>tail -f files/logs/live.log</code>. Note the word. <kbd>Ctrl</kbd>+<kbd>C</kbd> stops watching.</li>
<li>Challenge: <code>nano ~/notes.txt</code>, type <code>checked r1</code>, <kbd>Ctrl</kbd>+<kbd>O</kbd> <kbd>Enter</kbd> to save, <kbd>Ctrl</kbd>+<kbd>X</kbd> to leave.</li>
<li>Fill in answers/2.1.yml, then <code>make check T=2.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Text all the way down</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="logs-and-configs-are-text">Logs and configs are text</h3>
<p>Almost everything you read on a Linux machine or a router is a <strong>text file</strong>: lines of characters you can read
with your eyes. Configs, logs, scripts, the inventory an Ansible playbook reads. That&rsquo;s why a few small tools that
read text get you so far.</p>
<table>
  <thead>
      <tr>
          <th>Tool</th>
          <th>Shows you</th>
          <th>Good for</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>cat file</code></td>
          <td>the whole file at once</td>
          <td>short files</td>
      </tr>
      <tr>
          <td><code>less file</code></td>
          <td>the file a screen at a time, with search</td>
          <td>anything longer than a screen</td>
      </tr>
      <tr>
          <td><code>head -n 5 file</code></td>
          <td>the first 5 lines</td>
          <td>what a file starts with</td>
      </tr>
      <tr>
          <td><code>tail -n 5 file</code></td>
          <td>the last 5 lines</td>
          <td>the newest entries in a log</td>
      </tr>
      <tr>
          <td><code>tail -f file</code></td>
          <td>the last lines, then every new line as it&rsquo;s written</td>
          <td>watching a log live</td>
      </tr>
  </tbody>
</table>
<p class="lab-recap"><span class="mono">in one sentence</span> cat for short files, less for long ones, head and tail for the ends, tail -f to watch one grow.</p>
<h3 id="less-the-keys-you-need">less: the keys you need</h3>
<p><code>less</code> opens a file and waits for keys. It never changes the file.</p>
<table>
  <thead>
      <tr>
          <th>Key</th>
          <th>Does</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><kbd>Space</kbd> / <kbd>b</kbd></td>
          <td>a screen down / back up</td>
      </tr>
      <tr>
          <td><kbd>↓</kbd> <kbd>↑</kbd></td>
          <td>a line down / up</td>
      </tr>
      <tr>
          <td><code>/word</code> then <kbd>Enter</kbd></td>
          <td>search forward for <em>word</em>; <kbd>n</kbd> is the next match, <kbd>N</kbd> the one before</td>
      </tr>
      <tr>
          <td><kbd>g</kbd> / <kbd>G</kbd></td>
          <td>the first / the last line</td>
      </tr>
      <tr>
          <td><kbd>q</kbd></td>
          <td>quit</td>
      </tr>
  </tbody>
</table>
<h3 id="editing-in-a-terminal">Editing in a terminal</h3>
<p>In the codespace you can open any file in VS Code. On a server you reach with SSH, there&rsquo;s no VS Code, so you
need an editor that runs in the terminal. <strong>nano</strong> is the friendliest: it shows its own keys along the bottom.
<code>^O</code> means <kbd>Ctrl</kbd>+<kbd>O</kbd>.</p>
<table>
  <thead>
      <tr>
          <th>Keys</th>
          <th>Does</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><kbd>Ctrl</kbd>+<kbd>O</kbd>, then <kbd>Enter</kbd></td>
          <td>save (<em>write Out</em>)</td>
      </tr>
      <tr>
          <td><kbd>Ctrl</kbd>+<kbd>X</kbd></td>
          <td>leave. If you haven&rsquo;t saved, it asks first</td>
      </tr>
      <tr>
          <td><kbd>Ctrl</kbd>+<kbd>W</kbd></td>
          <td>search</td>
      </tr>
      <tr>
          <td><kbd>Ctrl</kbd>+<kbd>K</kbd> / <kbd>Ctrl</kbd>+<kbd>U</kbd></td>
          <td>cut a line / paste it</td>
      </tr>
  </tbody>
</table>
<p>Landed in <strong>vim</strong> by accident (a screen of <code>~</code> lines that ignores your typing)? Press <kbd>Esc</kbd>, type
<code>:q!</code> and <kbd>Enter</kbd>: that quits without saving.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> nano is a terminal editor that lists its own keys: Ctrl+O saves, Ctrl+X leaves.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>r1&rsquo;s log</h2>
  </header>
  <div class="lab-stage-body">
    <p>The top and the bottom of <code>files/logs/r1.log</code>, a log recorded from this lab&rsquo;s router:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ head -n 3 files/logs/r1.log
</span></span><span class="line"><span class="cl">*Nov 11 05:42:28.266: %CAPEOS-5-RESTART: CapeOS 0.11.0 started
</span></span><span class="line"><span class="cl">*Nov 11 05:42:32.023: %CAPEOS-5-LOGIN_OK: Login by admin from 172.80.102.1 port 60330
</span></span><span class="line"><span class="cl">*Nov 11 05:42:33.264: %CAPEOS-3-LINK_DOWN: Interface GigabitEthernet2 is down (administratively)
</span></span><span class="line"><span class="cl">$ tail -n 2 files/logs/r1.log
</span></span><span class="line"><span class="cl">*Nov 11 05:44:03.607: %CAPEOS-5-LOGIN_OK: Login by admin from 172.80.102.1 port 35784
</span></span><span class="line"><span class="cl">*Nov 11 05:44:04.722: %CAPEOS-5-CONFIG_DONE: Configured from console by root
</span></span></code></pre></div><p>Every line has the same shape, which is what makes logs easy to search:</p>
<table>
  <thead>
      <tr>
          <th>Part</th>
          <th>Means</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>*Nov 11 05:42:33.264</code></td>
          <td>when it happened</td>
      </tr>
      <tr>
          <td><code>%CAPEOS-3-LINK_DOWN</code></td>
          <td>who said it (<code>CAPEOS</code>), how serious it is (<code>3</code>: the lower, the worse) and the <strong>event</strong></td>
      </tr>
      <tr>
          <td><code>Interface GigabitEthernet2 is down ...</code></td>
          <td>what happened, in words</td>
      </tr>
  </tbody>
</table>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Read the log, then watch one grow</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>The first and the last line:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">head -n <span class="m">1</span> files/logs/r1.log
</span></span><span class="line"><span class="cl">tail -n <span class="m">1</span> files/logs/r1.log
</span></span></code></pre></div><p>Their events, the words after <code>%CAPEOS-5-</code>, go in <code>first_event</code> and <code>last_event</code>.</p>
</li>
<li>
<p>Open the whole log in <code>less</code> and search it. Type <code>/GigabitEthernet1</code> and press <kbd>Enter</kbd>: less jumps
to the first line that mentions it, and highlights it. Press <kbd>n</kbd> to see the next one.</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">less files/logs/r1.log
</span></span></code></pre></div><p>When did GigabitEthernet1 first go down (<code>LINK_DOWN</code>)? Its time, like <code>05:42:55</code>, goes in <code>gi1_down_time</code>.
Press <kbd>q</kbd> to come out.</p>
</li>
<li>
<p>Now a log that&rsquo;s still being written. Start the lab&rsquo;s live feed, then watch it:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">make live
</span></span><span class="line"><span class="cl">tail -f files/logs/live.log
</span></span></code></pre></div><p>A new line appears every 3 seconds. One of them says <em>the word is &hellip;</em>: that word goes in <code>live_word</code>.
<code>tail -f</code> keeps watching until you stop it with <kbd>Ctrl</kbd>+<kbd>C</kbd>. It doesn&rsquo;t change the file.</p>
</li>
<li>
<p>Fill in the four lines:</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>answers/2.1.yml</code><span class="lab-file-how">Ctrl+P → 2.1.yml</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">first_event</span><span class="p">:</span><span class="w"> </span><span class="l">RESTART</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">last_event</span><span class="p">:</span><span class="w"> </span><span class="l">CONFIG_DONE</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">gi1_down_time</span><span class="p">:</span><span class="w"> </span><span class="m">05</span><span class="p">:</span><span class="m">42</span><span class="p">:</span><span class="m">55</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">live_word: canyon      # yours is different</span><span class="p">:</span><span class="w"> </span><span class="l">the lab picks it when you run make live</span><span class="w">
</span></span></span></code></pre></div><p>Your <code>gi1_down_time</code> may differ if your copy of the log was recorded again; read it from yours.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>head</code> and <code>tail</code> read the ends, <code>less</code> searches with <code>/</code>, <code>tail -f</code> follows a file as it grows.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>A note in nano</h2>
  </header>
  <div class="lab-stage-body">
    <p>Write a file called <code>notes.txt</code> in your <strong>home folder</strong> with nano, with one line in it: <code>checked r1</code>. Then
<code>cat</code> it to make sure it saved, and run <code>make check T=2.1</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p><code>nano ~/notes.txt</code> opens it, and makes it if it isn&rsquo;t there yet. Type the line.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Saving is <kbd>Ctrl</kbd>+<kbd>O</kbd>, and nano then asks for the file name with the name already filled in:
press <kbd>Enter</kbd>. <kbd>Ctrl</kbd>+<kbd>X</kbd> leaves.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">nano ~/notes.txt          <span class="c1"># type: checked r1, then Ctrl+O, Enter, Ctrl+X</span>
</span></span><span class="line"><span class="cl">cat ~/notes.txt
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">checked r1
</span></span></code></pre></div><p>nano works the same on every Linux server you&rsquo;ll SSH into, including ws1 and srv1 in chapter 8. The codespace
also has VS Code, and <code>code ~/notes.txt</code> opens the same file there.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Paths</title><link>https://networkdoodles.com/labs/linux-cli-101/task-1-2/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-1-2/</guid><description> new to this? step by stepbeginner cd files/site, then ls, cd into folders, cd .. to come back up, and pwd whenever you’re lost. Find chi-leaf2.cfg. Its absolute path is pwd plus its name. cd files/site/nyc/rack1. Which path, with .., gets from there to the file? Try it with cat. Fill in answers/1.2.yml, then make check T=1.2. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li><code>cd files/site</code>, then <code>ls</code>, <code>cd</code> into folders, <code>cd ..</code> to come back up, and <code>pwd</code> whenever you&rsquo;re lost.</li>
<li>Find chi-leaf2.cfg. Its absolute path is <code>pwd</code> plus its name.</li>
<li><code>cd files/site/nyc/rack1</code>. Which path, with <code>..</code>, gets from there to the file? Try it with <code>cat</code>.</li>
<li>Fill in answers/1.2.yml, then <code>make check T=1.2</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>Two ways to say where a file is</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="absolute-and-relative">Absolute and relative</h3>
<p>The same file has many names, depending on where you start.</p>
<ul>
<li>An <strong>absolute</strong> path starts at <code>/</code> and lists every folder down to the file. It means the same thing
wherever you are, which is why scripts and config files use them.</li>
<li>A <strong>relative</strong> path starts from your working directory, the folder <code>pwd</code> prints. It&rsquo;s shorter, and it&rsquo;s
what you type most of the time.</li>
</ul>
<p>Two names help you move around in relative paths:</p>
<table>
  <thead>
      <tr>
          <th>Name</th>
          <th>Means</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>.</code></td>
          <td>this folder</td>
      </tr>
      <tr>
          <td><code>..</code></td>
          <td>the folder above this one. <code>../..</code> is two folders up</td>
      </tr>
      <tr>
          <td><code>~</code></td>
          <td>your home folder (not relative: it always means the same place)</td>
      </tr>
  </tbody>
</table>
<p class="lab-recap"><span class="mono">in one sentence</span> Absolute paths start at /. Relative paths start where you are, and .. climbs one folder up.</p>
<h3 id="tab-does-the-typing">Tab does the typing</h3>
<p>Press <kbd>Tab</kbd> after the first few letters of a file or folder name, and the shell finishes it for you.
Press it twice when nothing happens, and it lists what could come next. It&rsquo;s faster, and it never makes a typo,
so paths you build with <kbd>Tab</kbd> are paths that exist.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>Walking the tree</h2>
  </header>
  <div class="lab-stage-body">
    <p><code>ls -R</code> lists a folder and everything under it (<code>-R</code> is <em>recursive</em>):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ ls -R files/site
</span></span><span class="line"><span class="cl">files/site:
</span></span><span class="line"><span class="cl">chi  nyc
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">files/site/chi:
</span></span><span class="line"><span class="cl">README.txt  rack1  rack2
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">files/site/chi/rack1:
</span></span><span class="line"><span class="cl">chi-leaf1.cfg
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">files/site/chi/rack2:
</span></span><span class="line"><span class="cl">chi-leaf2.cfg
</span></span><span class="line"><span class="cl">...
</span></span></code></pre></div><p>From <code>files/site/nyc/rack2</code>, one folder up is <code>files/site/nyc</code>, so <code>../README.txt</code> is nyc&rsquo;s README:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ cd files/site/nyc/rack2
</span></span><span class="line"><span class="cl">$ cat ../README.txt
</span></span><span class="line"><span class="cl">The nyc site: one leaf switch in each rack.
</span></span></code></pre></div>
  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Up and down the tree</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>See the whole tree at once:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ls -R files/site
</span></span></code></pre></div></li>
<li>
<p>Walk down into one rack. Type <code>cd files/si</code>, press <kbd>Tab</kbd>, then <code>n</code> and <kbd>Tab</kbd> again, and
watch the shell fill the names in:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> files/site/nyc/rack2
</span></span><span class="line"><span class="cl"><span class="nb">pwd</span>
</span></span><span class="line"><span class="cl">ls
</span></span></code></pre></div></li>
<li>
<p>Read a file one folder up, without leaving:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat ../README.txt
</span></span></code></pre></div></li>
<li>
<p>Climb back up, one folder at a time, and check where you are each time:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> ..
</span></span><span class="line"><span class="cl"><span class="nb">pwd</span>
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> ../../..
</span></span><span class="line"><span class="cl"><span class="nb">pwd</span>
</span></span></code></pre></div><p>You&rsquo;re back in the lab&rsquo;s folder.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>..</code> is the folder above; chain them (<code>../..</code>) to climb further, and Tab to type names you can trust.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Find chi-leaf2</h2>
  </header>
  <div class="lab-stage-body">
    <p>Fill in <strong>answers/1.2.yml</strong>:</p>
<ol>
<li><code>chi_leaf2_absolute</code>: the absolute path of <code>chi-leaf2.cfg</code>, wherever it is under <code>files/site</code>.</li>
<li><code>from_nyc_rack1</code>: a relative path to that same file, starting from <code>files/site/nyc/rack1</code>. Check it: <code>cd</code>
into that folder and <code>cat</code> your path. If it prints the config, it&rsquo;s right.</li>
<li><code>readme_from_chi_rack2</code>: a relative path to <code>files/site/chi/README.txt</code>, starting from
<code>files/site/chi/rack2</code>.</li>
<li><code>parent_of_home</code>: the absolute path of the folder your home folder is in.</li>
</ol>
<p>Then come back to the lab&rsquo;s folder (<code>cd /workspaces/linux-cli-101</code>, or <code>cd -</code>) and run <code>make check T=1.2</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>For the absolute path, <code>cd</code> into the folder that holds the file and run <code>pwd</code>. Add <code>/chi-leaf2.cfg</code> to what it
prints.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>From <code>nyc/rack1</code>, how many folders up do you have to go before <code>chi</code> is in sight? Each one is a <code>..</code>.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>Your home folder is <code>/home/vscode</code>. Its parent is one step up the same path.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">chi_leaf2_absolute</span><span class="p">:</span><span class="w"> </span><span class="l">/workspaces/linux-cli-101/files/site/chi/rack2/chi-leaf2.cfg</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">from_nyc_rack1</span><span class="p">:</span><span class="w"> </span><span class="l">../../chi/rack2/chi-leaf2.cfg</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">readme_from_chi_rack2</span><span class="p">:</span><span class="w"> </span><span class="l">../README.txt</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">parent_of_home</span><span class="p">:</span><span class="w"> </span><span class="l">/home</span><span class="w">
</span></span></span></code></pre></div><p>From <code>files/site/nyc/rack1</code>, the first <code>..</code> is <code>files/site/nyc</code> and the second is <code>files/site</code>, where <code>chi</code>
lives. On a laptop, the absolute path starts wherever you cloned the lab.</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item><item><title>Where am I?</title><link>https://networkdoodles.com/labs/linux-cli-101/task-1-1/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/labs/linux-cli-101/task-1-1/</guid><description> new to this? step by stepbeginner Open a terminal: Ctrl+`. It starts in the lab’s folder. pwd, then cd ~ and pwd again: the lab’s folder and your home folder. cd - goes back. cat /etc/os-release: the PRETTY_NAME line is the operating system. ls files, then ls -a files: the name that only appears with -a is the hidden file. Challenge: ls --help, and ls /. Fill in answers/1.1.yml, then make check T=1.1. more in meet the lab</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<details class="lab-basics">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/></svg>
 <span>new to this? step by step</span><em>beginner</em></summary>
  <div class="lab-basics-body">
    <ol>
<li>Open a terminal: <kbd>Ctrl</kbd>+<kbd>`</kbd>. It starts in the lab&rsquo;s folder.</li>
<li><code>pwd</code>, then <code>cd ~</code> and <code>pwd</code> again: the lab&rsquo;s folder and your home folder. <code>cd -</code> goes back.</li>
<li><code>cat /etc/os-release</code>: the PRETTY_NAME line is the operating system.</li>
<li><code>ls files</code>, then <code>ls -a files</code>: the name that only appears with <code>-a</code> is the hidden file.</li>
<li>Challenge: <code>ls --help</code>, and <code>ls /</code>.</li>
<li>Fill in answers/1.1.yml, then <code>make check T=1.1</code>.</li>
</ol>

    <p class="lab-basics-more mono">more in <a href="/labs/basics/">meet the lab</a></p>
  </div>
</details>


<section class="lab-stage lab-stage-explain" id="explain">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">1</span>
    <span class="lab-stage-kind mono">explain</span><h2>The shell, and one tree of files</h2>
  </header>
  <div class="lab-stage-body">
    <h3 id="what-youre-typing-into">What you&rsquo;re typing into</h3>
<p>The window at the bottom of VS Code is a <strong>terminal</strong>. Inside it runs a <strong>shell</strong>: the program that reads what
you type, runs it, and shows you what it printed. This lab&rsquo;s shell is <strong>bash</strong>, the one on almost every Linux
server. <a href="/labs/basics/#terminal">Meet the lab</a> showed you <code>pwd</code>, <code>ls</code>, <code>cd</code> and <code>cat</code>; this chapter is about
what they tell you.</p>
<p>A command line has three kinds of words:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">ls  -la  files
</span></span><span class="line"><span class="cl">│   │    └── an argument: what to work on
</span></span><span class="line"><span class="cl">│   └─────── options: how to do it (-l long listing, -a all files)
</span></span><span class="line"><span class="cl">└─────────── the command
</span></span></code></pre></div><p class="lab-recap"><span class="mono">in one sentence</span> A command, then options that change how it works, then arguments that say what it works on.</p>
<h3 id="one-tree-starting-at-">One tree, starting at /</h3>
<p>Linux has no <code>C:</code> or <code>D:</code> drive. Every file on the computer hangs from one tree, and the top of it is called
<strong>/</strong> (the <em>root</em>). A <strong>path</strong> says how to walk the tree to a file, folder by folder, with a <code>/</code> between each:</p>
<table>
  <thead>
      <tr>
          <th>Path</th>
          <th>What it is</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>/</code></td>
          <td>the top of the tree</td>
      </tr>
      <tr>
          <td><code>/etc</code></td>
          <td>system settings, as text files</td>
      </tr>
      <tr>
          <td><code>/var/log</code></td>
          <td>the logs</td>
      </tr>
      <tr>
          <td><code>/home/vscode</code></td>
          <td>your <strong>home folder</strong>: yours to fill. <code>~</code> is short for it</td>
      </tr>
      <tr>
          <td><code>/workspaces/linux-cli-101</code></td>
          <td>the lab&rsquo;s folder, where Codespaces put the repository</td>
      </tr>
  </tbody>
</table>
<p>A path that starts with <code>/</code> is <strong>absolute</strong>: it works from anywhere. One that doesn&rsquo;t is <strong>relative</strong>: it starts
from the folder you&rsquo;re in now, your <strong>working directory</strong>, which <code>pwd</code> (<em>print working directory</em>) prints.</p>
<p class="lab-recap"><span class="mono">in one sentence</span> An absolute path starts at /; a relative one starts wherever you are now.</p>
<h3 id="hidden-files">Hidden files</h3>
<p>A file whose name starts with a dot, like <code>.bashrc</code>, is <strong>hidden</strong>: <code>ls</code> leaves it out unless you ask for
<em>all</em> with <code>-a</code>. Nothing about the file is secret. It&rsquo;s a convention to keep settings files out of the way.</p>

  </div>
</section>


<section class="lab-stage lab-stage-show" id="show">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">2</span>
    <span class="lab-stage-kind mono">show</span><h2>What the codespace says</h2>
  </header>
  <div class="lab-stage-body">
    <p>A new terminal, in the lab:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">vscode ➜ /workspaces/linux-cli-101 (main) $ pwd
</span></span><span class="line"><span class="cl">/workspaces/linux-cli-101
</span></span><span class="line"><span class="cl">vscode ➜ /workspaces/linux-cli-101 (main) $ ls
</span></span><span class="line"><span class="cl">Makefile  README.md  answers  captures  checks  files  hosts.txt  lab  reports  requirements.txt  scripts
</span></span></code></pre></div><p>The prompt itself already says who you are (<code>vscode</code>, the lab&rsquo;s user), where you
are, and which Git branch the folder is on. The bit you type starts after the <code>$</code>.</p>
<p><code>ls -la files</code>, the long listing of <em>all</em> files:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">total 36
</span></span><span class="line"><span class="cl">drwxr-xr-x  7 vscode vscode 4096 Nov 11 05:51 .
</span></span><span class="line"><span class="cl">drwxr-xr-x 14 vscode vscode 4096 Nov 11 05:52 ..
</span></span><span class="line"><span class="cl">-rw-r--r--  1 vscode vscode   77 Nov 11 05:51 .lab-notes
</span></span><span class="line"><span class="cl">drwxr-xr-x  4 vscode vscode 4096 Nov 11 05:52 backups
</span></span><span class="line"><span class="cl">drwxr-xr-x  2 vscode vscode 4096 Nov 11 05:51 configs
</span></span><span class="line"><span class="cl">-rw-r--r--  1 vscode vscode  191 Nov 11 05:51 labinfo
</span></span><span class="line"><span class="cl">drwxr-xr-x  2 vscode vscode 4096 Nov 11 05:51 logs
</span></span><span class="line"><span class="cl">...
</span></span></code></pre></div><p>A <code>d</code> at the start of a line is a folder (a <em>directory</em>); a <code>-</code> is a file. <code>.</code> is the folder itself and <code>..</code> is
the one above it; every folder has both. Chapter 4 reads the rest of each line.</p>

  </div>
</section>


<section class="lab-stage lab-stage-follow" id="follow">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">3</span>
    <span class="lab-stage-kind mono">follow along</span><h2>Find your bearings</h2>
  </header>
  <div class="lab-stage-body">
    <ol>
<li>
<p>Open a terminal of your own: <kbd>Ctrl</kbd>+<kbd>`</kbd>, or <em>Terminal → New Terminal</em>. Where does it
start?</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">pwd</span>
</span></span></code></pre></div></li>
<li>
<p>Go home, ask again, then come back. <code>cd</code> with <code>~</code> (or with nothing at all) goes home; <code>cd -</code> goes back to
wherever you were before:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> ~
</span></span><span class="line"><span class="cl"><span class="nb">pwd</span>
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> -
</span></span></code></pre></div></li>
<li>
<p>Which Linux is this? Most distributions describe themselves in one small text file:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat /etc/os-release
</span></span></code></pre></div><p>Read the <code>PRETTY_NAME=</code> line.</p>
</li>
<li>
<p>Look in <code>files/</code>, first the normal way, then with the hidden files:</p>
<div class="lab-file lab-file-run mono">
  <span class="lab-file-kind">run in the terminal</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ls files
</span></span><span class="line"><span class="cl">ls -a files
</span></span><span class="line"><span class="cl">cat files/.lab-notes
</span></span></code></pre></div></li>
<li>
<p>Open <strong>answers/1.1.yml</strong> (<kbd>Ctrl</kbd>+<kbd>P</kbd>, type <code>1.1.yml</code>) and fill in the follow-along
lines. Paths are absolute; the operating system goes in without its quotes:</p>
<div class="lab-file lab-file-edit mono">
  <span class="lab-file-kind">edit</span><code>answers/1.1.yml</code><span class="lab-file-how">Ctrl+P → 1.1.yml</span>
</div>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">home</span><span class="p">:</span><span class="w"> </span><span class="l">/home/vscode</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">repo</span><span class="p">:</span><span class="w"> </span><span class="l">/workspaces/linux-cli-101</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">os</span><span class="p">:</span><span class="w"> </span><span class="l">Debian GNU/Linux 12 (bookworm)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">hidden_file</span><span class="p">:</span><span class="w"> </span><span class="l">.lab-notes</span><span class="w">
</span></span></span></code></pre></div><p>On a laptop, <code>repo</code> is wherever you cloned the lab: write what <code>pwd</code> printed. Save with
<kbd>Ctrl</kbd>+<kbd>S</kbd>.</p>
</li>
</ol>
<p class="lab-recap"><span class="mono">in one sentence</span> <code>pwd</code> says where you are, <code>cd ~</code> takes you home, <code>ls -a</code> shows the files whose names start with a dot.</p>

  </div>
</section>


<section class="lab-stage lab-stage-challenge" id="challenge">
  <header class="lab-stage-head">
    <span class="lab-stage-n mono">4</span>
    <span class="lab-stage-kind mono">challenge</span><h2>Ask the command</h2>
  </header>
  <div class="lab-stage-body">
    <p>You don&rsquo;t have to remember every option. Almost every command explains itself.</p>
<ol>
<li><code>ls -l</code> prints sizes in bytes. Which option makes it print them as <code>4.0K</code> and <code>1.2M</code> instead? Find it in
<code>ls --help</code>. It&rsquo;s a long list: <code>ls --help | less</code> lets you scroll it with the arrow keys, and <kbd>q</kbd>
quits. Put the option in <code>ls_sizes_option</code>.</li>
<li><code>ls /</code> lists the top of the tree. Which of those folders holds the system&rsquo;s logs? Write its absolute path
in <code>logs_folder</code>, then try <code>ls</code> on it.</li>
</ol>
<p>Then run <code>make check T=1.1</code>.</p>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>In <code>ls --help</code>, look for the word <em>human</em>. <code>man ls</code> is the longer manual page for the same thing.</p>
</div>
</details>
<details class="lab-hint">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg>
 <span>hint</span></summary>
  <div class="lab-hint-body"><p>The logs folder is two levels down: a short folder name, then <code>log</code>.</p>
</div>
</details>
<details class="lab-solution">
  <summary class="mono"><svg class="ico" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
 <span>show the solution</span></summary>
  <div class="lab-solution-body">
    <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">ls_sizes_option</span><span class="p">:</span><span class="w"> </span>-<span class="l">h</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">logs_folder</span><span class="p">:</span><span class="w"> </span><span class="l">/var/log</span><span class="w">
</span></span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">  -h, --human-readable       with -l and -s, print sizes like 1K 234M 2G etc.
</span></span></code></pre></div><p><code>ls -lh</code> is the combination you&rsquo;ll type most. <code>--help</code> is the short version that almost every command has;
<code>man ls</code> is the manual, with every option explained (<kbd>q</kbd> quits it too).</p>
  </div>
</details>

  </div>
</section>

]]></content:encoded></item></channel></rss>