🚀 LAUNCHING A THING TODAY 🚀

My friend @ellane and I are pleased to launch a new mini-course:

🧑‍💻 Ellane learns the command line 🧑‍💻

She mentioned this to me a while ago, so we're going to do it live on Mastodon. Here, in this thread. We're thinking of it like a correspondence course.

You can't fit that much in a post, and formatting here isn't great, so the full posts will be on our mini blog at:

commandline.johnnydecimal.com.

We'd love you to follow along.

#LearnCLI

in reply to Johnny ‘Decimal’ Noble

01. Introduction & goals

On Mastodon, @ellane mentioned that she'd like to 'learn the command line'. What she told Johnny was that she wants to:

- understand what the command line IS
- learn how not to stuff up your machine
- learn what language it speaks
- understand what commands DO, where things go
- what's Homebrew, and why use it and what does it do, and how does it do it?

#LearnCLI

commandline.johnnydecimal.com/…

in reply to Johnny ‘Decimal’ Noble

02. What is the command line?

A very high-level introduction to the command line. What even is it? Why would we use it?

You can click a button because some designer in Seattle designed the program to have a button.

But what if you want more granular control? What if there isn't a button for the thing you want to do?

Then you crack open the command line.

Over to you, @ellane.

#LearnCLI

commandline.johnnydecimal.com/…

in reply to Johnny ‘Decimal’ Noble

Thanks, Johnny, this is outrageously exciting to my aspiring-geeky heart!

So I've done my assignment re- layers of abstraction. Makes perfect sense.

Just like my car's ignition button, I'm aware there's an organised, predictable series of events that take place once the button is pushed. Each event relies on those that came before it (pistons, oil, petrol, etc), but I don't have to think of any of that when I'm buckling up.

Computers be no different!

#LearnCLI

This entry was edited (1 year ago)
in reply to Ellane

04. Let me show you around your new car

@ellane Oh good analogy! That's going to be helpful.

Learning 'the command line' is like learning how to drive. But before we can drive, we need a vehicle.

Let me show you around your new car.

#LearnCLI

commandline.johnnydecimal.com/…

This entry was edited (1 year ago)
Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Hmm no, this is not normal.

Here's a little video. I type out `printenv`, hit return, see the result, hit return a few times, do it again. This is what should happen.

You're saying after your first screen of results the window becomes unresponsive?

Try typing vs. pasting, though that shouldn't matter.

share.cleanshot.com/kR2SZnj9

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

06. The structure of a command @ellane

Commands are all structured in the same way. They all follow one of a few patterns. When you learn those patterns, you learn the syntax of _all commands_.

We know that `pie lunch cook` isn't a valid sentence, even if we're not a chef.

And soon you'll immediately recognise that `--food pie &meal lunch cook` couldn't ever be a valid command: it just doesn't _look_ right.

#LearnCLI

commandline.johnnydecimal.com/…

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

08. File paths @ellane

File paths are core to this whole experience: many things you do involve a file, or being in a specific folder before you take an action. So let's go a bit deeper.

This lesson introduces ~, ., .., and /. Tiny symbols but they mean so much!

We also talk about relative vs. absolute file paths.

#LearnCLI

commandline.johnnydecimal.com/…

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

10. Escape arguments, completely.

By trying to `cd` to a folder with a space in it, you've accidentally given that command two arguments.

So let's talk about **arguments** and what they are. Then I'll show you two ways to get round this problem without renaming_every_folder:

1. Escaping with `\`.
2. Tab autocompletion.

The first is something you need to know. The second is something you'll actually use!

#LearnCLI @ellane

commandline.johnnydecimal.com/…

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

12. Case-sensitivity, ttys, and the prompt.

There’s a bit of feedback here, so I’ve made one post addressing these questions. And in the next post we’ll continue with the concepts.

Case-sensitivity: is your macOS case-sensitive? (A: kinda.)

ttys000: what is it? (A: 1800s technology.)

% vs. $: why? (A: style. 🕺🏽)

@ellane #LearnCLI

commandline.johnnydecimal.com/…

in reply to Johnny ‘Decimal’ Noble

13. Flags and options.

We almost understand the syntax of a command. To recap, we've met the command, and its (often optional) arguments.

Now let's meet flags and options, which are two sides of the same coin. They modify the _behaviour_ of a command.

@ellane #LearnCLI

commandline.johnnydecimal.com/…

Unknown parent

mastodon - Link to source

Constantin (he/him)

Hi both, just wanted to say thank you for this open and transparent communication about this learning experience!

I work in IT for some time and its not only a great reminder on how things work but also how many things are logical and others are ambiguous and sometimes confusing. 🙏😌

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

15. Less is more.

Let's learn how to view plain text files. Do you have any of those handy?

Oh wait.

---

Then we'll use this same skill to explore the system's built-in 'manual pages', which are more up-to-date than the web link I sent you last time.

These pages are a treasure-trove of information. They tell you, in great detail, how to use any command.

@ellane #LearnCLI

commandline.johnnydecimal.com/…

Unknown parent

mastodon - Link to source

Constantin (he/him)

I have a question, which is slightly off-topic:

It looks like you have been less technical person in the past? If yes: How do you look on IT and apps, now that you took the red pill and left the matrix?

Do you think that "apps should just do their magic" or that this will help you achieve more? Do you believe that programming or IT Stuff is much more different that you thought and now want to unlearn about the truth?

Im just curious on your perception. 😌

Unknown parent

mastodon - Link to source

Constantin (he/him)

Thanks for your reply, I fully agree that it will take some more time to fully identify the impact of this exercise.

Needed to ask it early on, it might sit in the back your head so you can tell me closer to the end. 😉🙏

(I started programming as a hobby again after 12 years and I see for myself how the different the world is or how rusty I have become? 😬😅

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Not at all! This is a whole other world here.

In the years running up to 2018 I tried and stalled and tried and failed to start learning some sort of programming language. Started one, stopped. Changed my mind. Started another.

So many times.

The one thing that finally got me was a JavaScript course, sadly now gone*, by a Google engineer. You should have seen how slowly he went.

Pain. Stakingly. Slowly. Like proper baby-steps slowly.

*It was free and now it’s $300/month.

1/5

This entry was edited (1 year ago)
in reply to Johnny ‘Decimal’ Noble

And that’s what I needed. That was the ah-ha moment.

Now I can do JavaScript, to an okay standard. Nowhere near many people, but good enough for what I need to do.

I still lean on the web. But because I understand the fundamentals, what I find myself needing is the pointer.

I’m in a dark room and you just need to put my hand on the switch. Then I can do the rest myself.

That’s what we’re going for here.

Fundamentals. Deep understanding.

Slowly. Until the light comes on.

2/5

This entry was edited (1 year ago)
in reply to Johnny ‘Decimal’ Noble

I just realised something! You have access to Learn Excel with Lucy.

Re-watch ‘Functions & Formulas’, and in pt. 2 pay close attention to the TEXTJOIN function.

_Syntactically_ it’s totally different to the CLI.

_Conceptually_ it’s **identical**.

- What’s the command?
- Does it have flags?
- Does it have options?
- Does it take arguments?

This is the thing about computers, and languages: once you internalise the _idea_, the rest is just translation.

4/5

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Great. Yeah I was going to write a short summary post to reinforce what’s important to focus on and what’s not. I’ll do it here.

Important:
- The basic <command> <flags/options> <argument> idea.
- This is such a massive leap from clicking a mouse.
- We’ll do a LOT more of this over time.
- Viewing a document; getting around inside there.

Not important:
- Any of the specific flags or arguments to any particular command.
- None of the contents of the man pages! Scary nonsense.

in reply to Johnny ‘Decimal’ Noble

Okay, terribly late on this one, and I still haven’t written a proper post for our little site. But I figure if I just type this at the kitchen table rather than agonising over perfection, that’s probably better.

(I will update the site later.)

So we’re going to ‘pivot’, as we say in the tech industry. I set out to teach you ‘the CLI’, but that’s a _massive_ undertaking, and your actual goal is to ‘learn plain text accounting, specifically hledger’.

Rather than possibly useless…

1/x

in reply to Johnny ‘Decimal’ Noble

…theory, therefore, we’re going to focus on the goal, and cover topics _as required_ on our way to that goal.

In your latest blog post you mentioned that you can read stuff, but you can’t yet edit. So let’s do that now.

Now, this qualifies as a ‘potentially dangerous’ command. Because if you edit the wrong file, you could mess something up! So just make sure you’re in the right place, and maybe create some test files to start.

The command 🥁 is 🥁

pico

2/x

in reply to Johnny ‘Decimal’ Noble

That’s it. You can just type `pico` and it’ll open.

And I’m going to leave you there. Because if you look around, I think you’ll work it out. The hints are all on-screen: see the bar along the bottom.

This is a pretty rudimentary text editor. It’s not the legendary `vim`. But it’s easy to use, and it’ll do the job.

And think about this: once this is all set up, there’s no reason to use the CLI to edit your plain text files. They’re just plain text files.

3/x

in reply to Johnny ‘Decimal’ Noble

You can use whatever you like to edit them. And just dive down to the CLI as required.

But still, I think this is a valuable exercise. So have a play with pico, create a few files, edit a few files, and let me know how you get on.

Next, we’re going to go straight for the hledger installation page. 😬

4/4

#LearnCLI

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Okay, we have two possibilities here.

Just like with any other text editor, you can either:
1. Open it ‘empty’, and start typing a new document, or
2. Open it with an existing document.

It never hurts to have a look at the first line of the man page, `man pico`:

`pico [ options ] [ file ]`

So:
- `pico`, then
- some optional [options], then
- optionally, a [file].

Ignoring the optional options, this gives us two paths... which might sound familiar?…

#LearnCLI

in reply to Johnny ‘Decimal’ Noble

Okay, let's turn in the direction of hledger. We're going to install it.

First, we need to install Homebrew. But first: what is it?

# Package managers

We're all used to installing software, and keeping that software up to date.

How do you install and keep updated applications for your Terminal? There are a bunch of ways, but Homebrew has become the de-facto standard for the Mac. Because it's just really nice.

commandline.johnnydecimal.com/…

#LearnCLI

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

So the purpose of Homebrew is just to install hledger. How might we do that?

Homebrew's web site is amazing so we might as well double-check. Head over there and search for hledger using the box at the top. You should find yourself on the formulae page for the app.

In this case, the page tells us exactly what we need to do:

`brew install hledger`

cl.jdcm.al/learn/19-install-so…
#LearnCLI

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Amazing progress!

So I'm going to throw caution to the wind — because it's Lucy's birthday today and I'm required out back to do chicken-related things — and give you the 'move a file' command.

Be careful with this one, because if you move the wrong file to the wrong place, there's no 'undo' in this world.

The command: `mv`, short for `move`.

And the same command serves as a rename! You just 'move' the file from its old name to its new name.

Check `man mv` but it's pretty obvious.

in reply to Johnny ‘Decimal’ Noble

The equivalent to copy a file is `cp`. Maybe create some dummy stuff on your desktop and mess about there for a bit.

When you're sick of that stuff, `rm` (remove) will delete it.

What happens if you try to remove a whole folder? Can you find the (potentially VERY dangerous) flag that allows you to 'recursively' delete an entire folder?

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Nice one!

As a rule, if something's already installed then brew isn't going to want to mess with it. Brew needs to install it so that brew can control it, because files are in different places and were installed in different ways.

So you could remove Firefox and re-install using brew to bring it under its control?

Those SHOUTY THINGS you can ignore.

And you can `brew update` then `brew upgrade` to do a manual upgrade of your installed apps at any time.

Unknown parent

mastodon - Link to source

Nate Dunn

Reading back through this and the emphasis on *precision* regarding case in the command line, I wondered what you thought about the "regional" spellings, such as "color" vs. "colour". Do both work? Does it bother you if one is preferred over the other? 🙂
Unknown parent

mastodon - Link to source

Nate Dunn

OK, here @ellane asks about Control-E vs Control-E, and @johnnydecimal settles on the side of "not case sensitive."

But in the previous lesson, "Less Is More," in learning how to navigate a text file with search, "To find the next instance of the same search, hit `n`. The previous, `N`."

Isn't that an example of case sensitivity? Or is that a rare exception? Seems akin to "`tab` to move forward, `shift-Tab` to move backward" in many forms... 🤔

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

@natedunnmi Feels like a default that the community has settled on over the years.

Control-[CHARACTER] = not case sensitive, i.e. Ctrl-n doesn't do a different thing to Ctrl-N. Therefore, pick a default, which is to express it as a captial. Maybe that's just clearer?

Whereas 'n' to go forward vs. ‘N' to to back, they're two different commands.

'n' without shift does one thing. 'n' with shift, that is to say ’N’, _does something different_.

Lots of this is just historical decisions…

in reply to Johnny ‘Decimal’ Noble

@natedunnmi Also note how Mac + Windows is explicit about 'Shift'.

Ctrl+E on a Mac, means ‘control and the E key’.

You want a shift in there, you have to say it. 'Ctrl-Shift-E’.

Oh yeah, and look at your menus! Copy = ⌘C. But you don't have to press Shift to get a capital C.

Paste and match style = ⌥⇧⌘V. Needs a Shift, so the Shift is explicit.

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

Okay let’s get back on this #LearnCLI horse!

Bookmarks. How do you move quickly to another folder?

1. Define an alias
You can create an ‘alias’ which is like a shortcut. You define <some short thing> which does <some longer thing>.

`alias m='cd ~/Movies'` creates an alias, m, which issues the command to take you to your Movies folder.

So you can create yourself an 'hl' alias, say, which changes you to your hledger folder.

Typing `alias` shows you your defined aliases.

1/x

in reply to Johnny ‘Decimal’ Noble

That's great, but you'll notice that these aliases aren't persistent: close the window and it's gone.

To make them persistent, we need to add them to a file which is run whenever a new prompt is launched.

This introduces your first 'dotfile'. So called because it starts with a dot.

Dotfiles are very common in CLI world. They're universally used as configuration files.

Because your system – including the macOS Finder – hides them by default. So they don't get in the way.

2/x

in reply to Johnny ‘Decimal’ Noble

This particular dotfile is called .zshrc, and it lives in your home folder. So – and I'm _so proud_ that you're using vim – let's edit that.

vim ~/.zshrc

You might already have one with stuff in it. If not, you'll just see an empty file. Either way, add your alias as a new line.

Hint: lines starting with # are comments. So you might add a section like this:

# Ellane's aliases
alias hl='cd ~/some/deep/path/to/hledger'

to keep things neat.

Save that, open a new window, and test.

3/x

in reply to Johnny ‘Decimal’ Noble

While we're in .zshrc, here's another quality-of-life improver that I always add to mine.

Normally when you press up-arrow to search through your history, it's just a dumb list of previous commands.

It's far more useful if you can type the start of a command you know you've previously typed, and have up-arrow search your history. To do that, add these lines:

# Enable history substring search
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward

4/x

This entry was edited (1 year ago)
in reply to Johnny ‘Decimal’ Noble

And one last hint: rather than having to open a new window every time, you can 'use' your .zshrc in the current window by typing:

source ~/.zshrc

Okay, this is just a quick one but I promise to stick with it now! And what I'll do is let it play out here for a bit, then summarise to the website.

Which, to remind our viewers, is commandline.johnnydecimal.com.

So! Tell me how you're getting on, and what you'd like to do next.

5/5

Unknown parent

mastodon - Link to source

Anita Lewis

It seems odd that the file was created new rather than having already been there. What do you see with

ls -a .zs*

It seems like there should have already been a .zshrc with something in it.

Also, somewhere in the back of my mind is the need to log off and back on for the change to work. Or you can use the command 'source ~/.zshrc' to make the change work I think.

Note: I know nothing about your OS, so I probably should stay out of this. It's just so puzzling.

This entry was edited (1 year ago)
Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

I wish you could do syntax highlighting here. It'd be nice to indicate exactly what's a command.

`Backticks`, being used for inline markdown, are often used to delimit the thing to be typed. In almost all cases you should not include them.

Sometimes people (or code blocks on websites) indicate a command with a $ at the front. That represents your prompt and should also not be typed.

(Sometimes when you copy the code block off a website the $ also gets copied! This is wrong.)

Unknown parent

mastodon - Link to source

Thorsten Zöller

There are many different kinds of shells, and most end with "sh" (standing simply for "shell") - like sh, bash, csh, tcsh, ksh, dash, fish etc. As far as I know, the "z" in "zsh" is the initial of someones name.

The "rc" stands for "run commands" (although there are different interpretations) and indicates that it is a configuration file.

Unknown parent

mastodon - Link to source

Anita Lewis

Not sure if you got your answer:
Yes there are quotation marks before the cd and at the end of it. These are around the command that ellane equals.

And on the next screen after saving this, notice that he typed

source .zshrc

That lets the shell see this change you've made. The other option is to log off and then login again.

Unknown parent

mastodon - Link to source

Johnny ‘Decimal’ Noble

lutetium is the name of this laptop, so that's just part of my prompt.

The alias I added was:

alias ellane="cd ~/Movies"

(Confusing things by using "double quotes vs. 'single last time. Sorry! But they both work the same.)

Then we exit vim and I 'source' that file to activate the new alias. Or I could have opened another shell.

Because this .zshrc file is run by every new shell on launch. That's what it's for. Hence putting a command in it will make it available in every new shell.

in reply to Johnny ‘Decimal’ Noble

So you'll want to add something like

alias hl="cd /path/to/your/hledger/directory"

Then save, either 'source' the file or launch a new shell, and then

hl

_should_ jump you there.

You can use the `echo` command to test your .zshrc is being executed. `echo` just types out text. Try it:

echo Help I am stuck in the computer!

So you can put an `echo` in your .zshrc and every time you launch a new shell, you should see what you wrote.