me.dm is part of the decentralized social network powered by Mastodon.
Ideas and information to deepen your understanding of the world. Run by the folks at Medium.

Administered by:

Server stats:

1.4K
active users

Learn more

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/

commandline.johnnydecimal.comThe structure of a commandOur first look at the fundamental structure of a command.

@johnnydecimal Okay, this feels like progress! I cd'd myself to the Documents folder on the first go, by typing in `cd Documents`, and used `ls` to see the list of items in that folder. Did the same with the Downloads folder, and was reminded (again) that I really need to clear that one out. I tried a number of things to `cd` to a specific nested folder, with no luck.

One of my attempts had an alarming result:

#LearnCLI (1/2) 🧵

@johnnydecimal When I could see the folder I wanted to `ls` in the `ls` of its parent folder, I typed `view [name of folder]`.
I should have known better than to experiment with unknown commands!

That gave me a blank page with a `1` at the top, and the word `Insert` at the bottom. Logout didn't work, so I committed the press-the-red-dot-to-close-the-window sin. No more jumping ahead of the teacher for me! (2/2) 🧵

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/

commandline.johnnydecimal.comFile pathsHow do we get around the file system if the folder we want isn't a direct subfolder of where we are?

@johnnydecimal I’ve managed to change directory to pretty much everywhere, which is cool! Got a bit carried away trying to see the contents of a folder quite deep in multiple subfolders, and got a **zsh: permission denied** message. This was puzzling until I realised I’d forgotten to preface the path with a command! (1/2)🧵

@johnnydecimal Something else I’ve noticed is that the CLI does *not* like word spaces. It returns a **too many arguments** message any time I try to access a folder with a multiple-word name. Is there any way around that, or do I have to rename_everything_to_remove_word_spaces?
Rather than renaming anything, I looked for paths with locations that were one word only and was able to `ls` the contents of the parent folder of the directory I was looking at. So far so good! (2/2)🧵

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/

commandline.johnnydecimal.comEscape arguments, completelyThe CLI doesn't handle spaces in file names very well. We use 'escaping' to work around it.

@johnnydecimal Escape Arguments Homework:

I successfully `cd`d to “A_folder_in_quotes” by typing `cd \”A` and then pressing <tab>

Then I navigated to a folder with word spaces inside my Obsidian vault, which is nestled four folders deep (don’t judge), and pressed <tab> to auto complete its name, which is ALL THE NOTES. Terminal completed the string like this: `cd ALL\ THE\ NOTES`. (1/4)🧵

@johnnydecimal It’s good to learn the why behind things that look different to my GUI-trained eyes.

I used to view things like slashes that went the wrong way and underscores between words as tech-virtue signalling: We’re More Technical and Clever Than You So We Wrap Things In Extra Bits Because We Can. Seems silly now! (4/4)🧵

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/

commandline.johnnydecimal.comCase-sensitivity, ttys, and the promptTwo follow-up questions.

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/

commandline.johnnydecimal.comFlags and optionsThe final piece of the command puzzle, we introduce 'flags' and 'options'.

@johnnydecimal Interesting podcast excerpt, thanks. It’s good to know about Macs having a different approach to case than other systems. Seems to me if we’re going to err, it should be on the side of precision—so I’ll play it safe by treating everything as case sensitive from now on.

Thanks for explaining the `ttys000`. I figured it wasn’t something I *needed* to know, but having that confirmed saves me from the distraction of wondering what it is every time I see it. (1/3)🧵

@johnnydecimal Just to check, I opened another window and yep, it said `tys001`.

I played with `ls -la` for different locations on my hard drive, and the `--color=always` one, too. The latter produced mostly one colour, with splashes of another here and there. I suppose we’ll get to the logic behind that later, if it’s important enough to discuss.

When displaying `ls -la` there’s a column on the left with information like `drwxr-xr-x@` that I don’t understand. (2/3)🧵

Nate Dunn

@ellane @johnnydecimal 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? 🙂

@natedunnmi I assumed that code would only recognise the US spelling, color, so that's the one I use.

…Just tried it out, and 'colour' is an unrecognized (not unrecognised) option.
@johnnydecimal