Sensei Tim teaches you the Linux command line

Published: 2020-09-05
Description: In a mystic room in my mother's basement, I teach you how to type commands into a terminal from the 80s.
Word count: ~7600

"I'm so sorry," says the blogger.

"Why?" you ask.

"Because this entire post is in second person," he says.

"But wouldn't that be totally unreadable, from a blog post stand point?"

The blogger begins to ironically shuffle dance while laying down on the floor. The elder of your village told you that this was the place to learn about the ancient art of the command line. Instead of finding him in a lost mountain, you actually met him in his literal mother's basement. It smells so bad that opening the door is a spiritual experience akin to swallowing dumpling without chewing.

"Please... Uh... Tim the Absurd. I am here to learn of the command line," you say, trying not to cry at the sight of that weird black shit in the corner of the room.

"What's the magic word?" he asks, picking at a hole in his pajama shirt. He might or might not be wearing pants.

"Is it 'please?'"

He lunges with perfect form, "sudo!"

In the beginning there was the terminal, and it was good

The Sensei Tim sits down on a bean bag chair and appraises you with sparkling madness in his eyes.

"Did you bring a computer?" he asks.

You lay down your backpack and pull out your laptop. You present it to him, and he inspects the craftsmanship.

"I suppose you already have Linux installed?" he says.

"What? No. It's got Windows 10."

The blogger drops the laptop like it had been a flaming hot potato. "You dare bring that hot batshit bull into my domain?!"

Shocked at the outburst, you take back the laptop and say, "I'll download a VM and get Linux on it right away!"

Tim was trying to eat an entire croissant before you finished your sentence, and is now too busy choking to respond.

After spending the next octovigintillion years trying to get WiFi working on your new Linux installation, you finally emerge from the cave (his closet).

"Now, my young apprentice," he says, clearly being younger than you are, "Launch your favorite terminal application and you shall learn."

"Will I be taught the deepest secrets of computers? Will I be a master programmer or a world class expert on computation?" You ask, eager and ready.

"Absolutely not," he says, "I will teach you only what is actually useful for getting work done, for that is all that I know myself. You probably won't be any more efficient than you are with your Windows installation."

"But then what's the point?" you ask, "Why even learn such an esoteric skill if it doesn't make me better than others?"

Tim stops typing and looks at you full on, "Not everything is about efficiency. This is about the enjoyment of using a computer. Some people are predisposed to like graphical interfaces, and others are predisposed to liking the terminal."

"But Sir Tim," you say, still confused, "What is it that brings you to the command line?"

"Consistent interface," he answers at once, "I can write a book, analyze my data, program an application, update my website, and study, all from the same semi-consistent interface. And even after that, this interface is only limited by your own skills instead of the whims of a UX designer. Once you find the rhythm of the terminal, I suspect you will feel the same way."

"Your wisdom is unparalleled," you say in awe, "Please teach me."

"'Kay."

The first command

You sit on the floor, next to the insane Sensei's beanbag chair, in such a position that you can see each other's screens. Each screen has a terminal opened.

"Sit down," says Tim.

"I already am, sir," you say.

"Oh right," he says, "Look at my screen, and read aloud what I type."

"Okay..."

$ echo hello

"I'm already confused," you say.

"That's fine," he says, "It will make sense once you obtain more context. For now, type echo hello into your own terminal and then press Enter."

$ echo hello
hello

"Oh!" you pontificate, "The second line happened automatically, and doesn't have that dollar sign in front!"

"Correct. The dollar sign is usually what is used to describe a command prompt. It may have other information in front of it, like your computer's username, but for now we will only worry about the dollar sign."

He gestures to your terminal screen with a churro, "Now replace the word hello with with any other word of your choosing, and observe the results."

You try it out:

$ echo lamp
lamp
$ echo green
green
$ echo command
command
$ echo echo
echo

"Does this only output the word you give it?" You ask, "It's like an echo chamber in here..."

"Not quite. What you're doing is using the echo command, while giving it different arguments, which change how a command works. echo happens to take whatever arguments you give it and repeat it back to you; you might also say that it prints its arguments."

"Okay..." you say, brain leaking onto the floor, "The name echo makes more sense, now; I was really confused about the name."

The old Sensei laughed, "Oh my poor poor apprentice. You haven't seen anything yet."

"I haven't?"

"No. Now try giving it more than one argument. Go ahead."

$ echo hello world
hello world

"It just prints everything after echo," you say.

"Close. You've actually given it two separate arguments, and the output just happens to make it look like that's what happened. Arguments are separated by spaces." He shows a picture of space on his own computer.

"Why have a command that prints what I just typed? Seems kind of useless..."

The blogger smiles and exposes the pet rock he embedded in place of one of this teeth, his voice echos across the field of un-vaccumed carpet in his room, "You'll see!"

You're salivating so much in excitement that it gets on the walls, and the Sensei has to clean up the mess. Jerk.

The second, and third, and millionth command

$ echo fdjsakflsdajkl dfjakfdjsaklfjkdla
fdjsakflsdajkl dfjakfdjsaklfjkdla
$ echo 123 432
123 423
$ echo command *
command Desktop Documents Downloads

"Sir! I think I found a bug!" You say, waking up Tim from his thousand millisecond slumber.

"Huh? Oh, right. Try typing it like echo command*, without the space."

$ echo command*
command*

"But what if I want the space?" you ask.

"Than type it like any of these ways."

$ echo command \*
$ echo command\ *
$ echo "command *"
$ echo 'command *'

"They all work," you say, "but why do I have to do it like this?"

The Sensei brings out a bottle of vodka and a bottle of wine, "Look here, and see that both these bottles will get you drunk. But one of them will taste one way, and one of them will taste another. Just like your choice of alcohol, you also have a choice of how you send commands to the command line. The same result, but different implementation."

"That's not what I'm asking," you say, watching in awe as he chugs the entire bottle of vodka, "I'm asking why the * does that weird thing in the first place."

"Ah," he sways a bit and throws the empty vodka bottle into the bottomless pit, "There are certain characters that have special meanings in different contexts. The asterisk, in that context, happens to expand into the names of all the files and folders in your directory."

"I don't understand. What does 'expand' mean in this? What's a directory?"

He puts a hand on your shoulder, mostly to steady himself than for comfort, "Oh man. I shouldn't have drank that much at once. Uh... Just know that there might be strange and arbitrary-looking rules for things. There is a very good reason for most of them, but it won't make any sense until quite a bit later."

"You say that a lot."

"Huh?" He had been looking at the wall.

"You say, 'You'll understand later,' a lot."

"Well, I'm trying to teach you in a logical order, but you keep rubbing up against things that require context from other later lessons. It'll make more sense with experience. And anyways, who's the Sensei here?"

"You're drunk," you say, "Maybe it's time to take a break?"

He swings an arm at a small ceramic llama on a bookshelf, "Never! Type ls into your terminal and press Enter! Do it at once!"

Afraid for the llama and also your life you do as you're told:

$ ls
Desktop Documents Downloads

"It's the same output as that asterisk besides the command part!"

Experimenting you try it with the echo command:

$ echo *
Desktop Documents Downloads

"Woah!"

"You're impressed by simple things," he puts a hand on your head trying not to sway, "That vodka is starting to kick in. Holy shit. Okay. Leeeets focus. Focus..."

"But drunken Sensei Tim," you say, "You said that the asterisk expands into the contents of a directory. Does ls also do this?"

"No..." he sits down hard on the floor, "You... Uh... You got any water? I should probably drink some water..."

You hand him the water bottle that was right next to him.

"Thanks! :D"

"Why did you say 'colon D'? Is that another command?"

"Shut up. Just shut up for the love of god."

You are silent while the command line master fumbles with the lid of the bottle.

Finally he takes a swig and says, "Alright! Fine! I'll fucking explain what's going on. echo prints all of it's arguments, right? When you put the asterisk there, it expanded into all the names of the files and directories in the directory you're in. Another way to look at it is the asterisk got replaced with all those things before being sent to the echo command. You follow?"

"No..."

"Good! Than maybe you'll learn your lesson to not learn your lesson!"

"What's going on?"

"Alternatively, the ls command -- standing for "list" -- simply lists the contents of your directory without doing any weird ass advanced level expansion logic. Jesus fuck. Satisfied now?"

"I... think so? So they just do the same thing, but in different ways?" The epiphany hits you, "Just like your lesson with the vodka! You're trying to tell me that there is always more than one way to do something when working the command line! You're so wise."

The Sensei Tim giggles while staring at the ceiling.

"But what is a directory?"

"What do you... Hold on," he holds up a finger while trying to move over to his laptop, "Alright. What do you think it is?"

"A collection of files and folders?"

"Right in one go. Try giving the ls command the -l argument."

You try it and find the output to be totally different. "I see," you say, "It's as you said. The arguments change how the command function."

The Sensei says, "Try giving it the argument of Documents and see what happens."

You try and become confused once more, "But nothing happened."

"That's because you don't have anything in your Documents folder. If there was something in there, ls would have listed it for you. Now try to run the command, cd Documents."

"The prompt changed!" You say, "It's telling me I'm in the Documents directory now, right?"

"What?" He had been scratching a hole in the wall with his fingernail, eyes glazed, "Yeah that's whats going on. Most prompts show you what directory you're in, but some of them don't. If you find yourself using a terminal that doesn't you can use the pwd command to tell you where you are."

$ pwd
/home/username/Documents

"But that isn't what the prompt says. The prompt says ~/Documents instead."

"Yeah. Actually, I'm kinda glad I taught you about expansion. Because the tilde, in many situations, expands into your home directory. That's just what it's doing here. ~/Documents is just an abbreviated form of /home/username/Documents. And you can use the tilde in place of /home/username in a large amount of situations."

"So what does pwd stand for, then?"

The Sensei sits there for a good 30 seconds before giving his answer, "I have no fucking clue."

"Surely there must be some sort of logic to it..."

"Surely," agrees the Sensei, "But it is beyond even my comprehension." He grabbed a sock and began to stretch it for no reason, giggling, "Tell me the power you have learned with these commands."

"I'm sorry, I don't know."

The Sensei sighes, puts down the sock, and begins to slowly type into his laptop. Even with the reduced coordination of the vodka, he still dosen't make any spelling mistakes.

$ ls
vid1.mkv not-porn.avi what-is-this.mp4
$ pwd
/home/tim/vids
$ cd ~
$ pwd
/home/tim
$ ls
docs vids downloads music pics
$ cd pics
$ ls
wallpapers screaming.png burning.jpg why.jpg

"You have now learned how to navigate a directory structure," he says, "Congratulations or whatever."

The world of possibilities exploded your mind, and the Sensei has to clean up the mess. Jerk.

Something about text and directories

The Sensei had woken up from his 18 hour nap, and was now ready to teach you more of the dark arts of the command line.

"Wait. You're telling me that you sat there for 18 hours going into various directories and nothing else?" He says.

"Yeah? I had to practice what you taught, Sensei."

"I- Wha- Huh?"

"I will be your most dedicated student," you say.

Tim puts his head in his hands and sits there for a while.

"Sensei?"

"Yes?"

"How might I make a file or directory?"

"Luckily for both of us, that's just the lesson I had planned," he says, head still in his hands.

"Is there something wrong Sensei?" you ask.

"No," he says, getting up, "Nothing at all. Go into your Documents directory-- Jesus that was fast! I guess you did practice it for 18 hours... Anyways. Now run the touch command with the argument of whatever file name you want."

$ touch ball.txt
$ ls
ball.txt

"A real file!" you say, "Wow!"

"Are you making fun of me? I think that's what's happening here. Nobody gets this excited over simple commands. Or navigates directories for 18 hours. You're here to mock me or something."

You entirely ignore this and instead make more files.

$ touch bird.mp3
$ touch game.exe
$ ls
ball.txt bird.mp3 game.exe

"It's a damn conspiracy..." he says, "Anyways, you're making a classic mistake of a Windows user here, can you spot it?"

"Are my file names not cool enough?"

"What? No. Why would you think that was the issue?"

"I just thought..."

"Whatever. Listen. Do you know what plaintext is?"

"No?"

Tim rips off a chunk of wall paper to reveal another layer of even uglier wall paper behind it. "Is this wall paper a fish?"

You inspect it and conclude, "It isn't a fish!"

"Right. Do you think if I threw it into a pond, it would become a fish?"

The problem is difficult, so you take a while to respond with, "No. I don't think so."

"That's what you're doing with these files names. You've told it to make an mp3, and yet on Linux that doesn't mean anything. File names on Linux can be anything you want. They don't need an extension. Any file can be made into an executable, whether or not it has a .exe extension."

"But how do you get an actual mp3?" You ask, fascinated.

"mp3's still work the same way as in Windows," he says, "They even keep the .mp3 extension. The difference is that mp3 files aren't plaintext. They aren't just letters and spaces and characters in a file, they're more complicated than that. You need special programs to make them and read them, which touch isn't."

"So if I tried to load bird.mp3 in my music player, it wouldn't work?"

"It would probably give an error."

"And .exe files don't work?"

"Not the way you expect. The '.exe' extension is made specifically for Windows programs."

You think about these revelations for exactly 1 minute and 20 seconds, the same amount of time that Tim can hold his breath for without passing out. Not that it's relevant to the discussion or anything. "What's plaintext?"

The Sensei Tim, gasping for air, says, "I just told you. It's simply characters in order. It's one of the most universal and basic formats in all of computing, and it will be the main thing you work with on the command line."

"So what I was doing was trying to tell a plaintext file to be a different kind of file, but that doesn't make it any less plaintext. The same as trying to make wall paper into a fish doesn't make it any less wall paper!"

"Correct."

"What about directories? What command makes those?" You ask.

"Try, mkdir with the argument being the name of the directory you want to make."

$ ls
ball.txt bird.mp3 game.exe
$ mkdir totally cool
$ ls
totally cool ball.txt bird.mp3 game.exe
$ cd totally cool
bash: cd: too many arguments

"Sensei! What did I do wrong?"

"Remember when I taught you that commands take arguments, and that arguments are separated by a space? What you've done is give mkdir two arguments, which makes a directory called totally and another called cool. You can't cd into more than one directory at a time."

"But what if I want to have a space in it?" You ask.

"It is considered proper form to not make files and directories with spaces in their names for this very reason. But if you absolutely insist, the easiest way is to put the argument into quotation marks. Like this:"

$ mkdir "totally cool"
$ cd "totally cool"
$ pwd
/home/tim/totally cool

"Putting it into quotations has the effect of making it into a single argument, instead of two separate ones."

You immediately throw up in awe of the awesome awe-inspiring power bestowed upon your brain, and the Sensei has to clean up the mess. Jerk.

Misdirection

The Sensei was in one of his moods again.

"Why the fuck is my web browser so damn slow? What the hell are they even doing over there at Mozilla? And don't even get me started on the phone apps I'm forced to use on a daily basis. I swear, the more powerful hardware becomes, the slower everything ends up being. Fuck this."

"Sensei Domo Tim Sama San," you say trying to placate his rage, "I have made many files and moved over vast directories. But I still do not know how to add plaintext to a file, nor how to read it from the command line."

"And why does it take so long- What did you say?"

"Sensei Domo Tim Sa-"

"No, after that."

"...from the command line."

"Before that."

"I have made many files-"

"I'm going to suplex you."

"How do I add and read plaintext on the command line?" You smile, happy you've distracted your Sensei from his rage.

"That shit eating grin tells me you already know the can of worms you've opened up," he says, gesturing besides his beanbag chair, ready to give another lesson.

"The only can of worms I've opened up is for my meals back at the village. I'm sorry Sensei."

Sensei Tim stares into the distance for a while, deep in thought, "What."

"The only can of wor-"

"No."

You wait for Sensei to gather his thoughts. You make some more files while you wait.

"Okay. We're just going to ignore that, you understand?"

"Yes Sensei."

Sensei brings out his own laptop. "Truth be told, there are as many ways to add text to a file as there are particles of water in the air, each one doing something slightly different," he says, "And what's worse, everyone has opinions on which is the best."

"Is this where I learn the ancient art of Vim, Sensei?"

Tim throws a sock stuffed with sand at a nearby wall, making it shatter, "No!"

"But Sensei. I've seen you use it on your own computer, and I've heard legends of masters being able to edit anything with ease. I wish to be as fully competent as you!" You say.

Tim throws another sock at the wall, this time stuffed with frozen green beans, shattering it, "Listen to me very carefully. vim and vi aren't just simple commands you can learn, they are fully fledged text editors! You're asking me the equivalent of teaching you piano while you're trying to learn to fly a plane. It could work, but it's out of the scope of your education right now."

You ponder this for a while. "What about Emacs?"

Tim throws a sock full of vitamin D3 supplements at the wall, shattering it, "No! It's the same issue. Editors like vim and emacs and even kakoune are powerful. But with that power comes a price of time investment that will derail us."

"But what shall I use, Sensei? What if I want to add text to a file?"

Tim picks up the shattered remains of sock from next to the wall, "If you must use a text editor, than use something like nano or gedit, which will be familiar and useful. But for these lessons, we won't use any editor."

He brings out his laptop once again, and shows you this:

$ touch text
$ ls
text
$ echo "Tim is the coolest guy ever" > text
$ cat text
Tim is the coolest guy ever

"Now don't go foaming at the mouth," he says, "I know there was a lot introduced at once there."

You hastily wipe the foam from your mouth before he sees.

"You already know what touch, ls, and echo do. The cat command, at its most basic level, is used to print text from a file into the terminal."

"Why is it called cat?" you ask, trying not to foam at the mouth more.

"Because the 'official' use -- and I use the word 'official' very loosely -- is to conCATenate files, which means to combine them together. If you give it more than one file in the arguments, it will output them both, in order, to the terminal with only a single command."

$ touch lol
$ ls
lol text
$ echo "Don't you agree?" > lol
$ cat text lol
Tim is the coolest guy ever
Don't you agree?
$ cat lol text
Don't you agree?
Tim is the coolest guy ever

You study the material that Sensei Tim has given. "So the > argument in echo tells it to output into a file, then."

Sensei smiles, "Close. But watch this."

$ ls
lol text
$ cat text lol > brutus
$ ls
brutus lol text
$ cat brutus
Tim is the coolest guy ever
Don't you agree?

"So cat can do it too? Also you didn't touch the file called brutus..."

"Hold that thought. This might blow your mind."

$ ls
brutus lol text
$ ls > files
$ ls
brutus files lol text
$ cat files
brutus files lol text
$ touch moar
$ ls
brutus files lol moar text
$ cat files
brutus lol moar text

You sit in shocked silence.

"When a command prints something to the terminal, it is called standard output. Remember that name, because it is one of the most important concepts I will teach you. So when you call the ls command, it prints the contents of your current directory into standard output."

You nod along, ignoring the foam entirely at this point.

"Likewise, cat simply takes the contents of files and prints them to standard output. echo takes its arguments and prints them to standard output. Anything that prints to the terminal is standard output. The > symbol isn't an argument to a command, it's a generic thing for all commands; what do you think it does instead?"

"It... takes standard output and puts it into a file?"

"Yep! And if that files doesn't exist, it'll also make the file for you, without you having to do touch. Anything that can print to standard output can also be written to a file."

You jump up and yell, "That's amazing! Such pragmatism!"

Sensei Tim calms you down by launching a small ping pong ball at your right abdomen, "Hold on, I'm not finished yet."

You sit down and observe Sensei's work.

$ cat text
Tim is the coolest guy ever
$ echo "THE BLACK GOAT OF THE WOODS!" > text
$ cat text
THE BLACK GOAT OF THE WOODS!

"Do you see what happened?"

"The old text went away," you say.

"Correct. > always overwrites the file," he puts on a wig on top of his stuffed pikachu, "Watch this."

$ cat text
THE BLACK GOAT OF THE WOODS!
$ echo "MOTHER OF A THOUSAND YOUNG!" >> text
$ cat text
THE BLACK GOAT OF THE WOODS!
MOTHER OF A THOUSAND YOUNG!

You sit there slack jawed, foam leaking everywhere.

"As opposed to >, using >> appends standard output into a file."

He shakes you out of your stupor using one of those dinosaur stick things used to grab things from far away, "Listen to me! This is called redirection. Did you hear that? Redirection! You're redirecting where standard output is going!"

"Wow..." You foam.

He puts down the beach ball full of orange juice he was wielding, "You see, redirection is where the real power of the command line comes in. There are many different kinds of redirection, and you'll be learning the most powerful one soon: the pipe."

You realize that the foam is all over the carpet, and the Sensei has to clean up the mess. Jerk.

This is why I like the pipe

A few days later Sensei Tim finally returns from the supermarket with more cleaning equipment.

He has a somber expression when he sits you down and says, "It's time."

"Time for what, Sensei?"

He pulls out a pipe cleaner from the cleaning equipment. You suddenly realize that pipe cleaners are called pipe cleaners because they are actually made to clean smoking pipes, and have been appropriated by kindergarten schools for arts and crafts instead. "Today," he glances over at the cleaning equipment, than sighs, "Today we're learning about pipes."

He hand you the pipe cleaner and you take it, "I thought we were learning about the command line?" you say.

"Huh? Of course we are. This is all just for... Well, I guess that would ruin it if I told you." He hands you another pipe cleaner, this one bright pink.

"Okay...?"

"Don't freak out and explode again or something," he says, speaking slowly and carefully, "Pipes are, without a doubt, my favorite thing about the command line. And they're the most powerful part of it, in my opinion."

You're focused, even though you have like 4 pipe cleaners in your hand. He hands you another one.

He eyes you carefully, like a locksmith appraising a locked smith, "But first I need to teach you another command. Are you ready for that?"

You nod eagerly, pipes in hand.

"Your enthusiasm is frightening," he says, "But alright. I've already prepared a file for this demonstration."

$ cat list
The one thing.
I know that two.
Three's a crowd.
$ grep 'two' list
I know that two.

You try to say something exciting, but you get distracted when he hands you another pipe cleaner. You've lost count; you've probably got more than 10, but less than 20.

"Okay. We're doing good. No freak outs yet or anything," he says, handing you another pipe cleaner, "grep is one of those really famous commands that everyone should know at least a little bit about. Its name has a bit of history, so we're just going to assume it makes sense."

"What does-" he hands you another pipe cleaner, "What does it do?"

"It searches a file for lines containing your search, and prints those lines to standard output. In the previous example, I searched for lines containing 'two' in the 'list' file, and it printed the only line with 'two' in it."

$ grep 'one' list
That one thing.
$ grep 'e' list
The one thing.
Three's a crowd.
$ grep 'three' list
$ 

"That last one didn't print anything," you say, trying not to drop your pipe cleaners.

"Right. Because grep is case sensitive by default. We searched for 'three' with a lower case 'T', while the one in the file is upper case. In fact, most things in Linux are case sensitive, so you might as well get used to it now."

"So when there isn't any match-" he hands you another pipe cleaner. He has a lot of them left and your hands are getting full, "There isn't any output?"

He nods, "Good catch."

"That has to be the most simple command ever! Just print the line with my search in it!" You say in between being handed pipe cleaners.

He flinches, than says, "Oh you sweet summer child..."

"What?"

"Nothing. We have enough information to discuss pipes now."

You contemplate exploding, but decide against it when handed another pipe cleaner. You tuck a few behind your ears to make room.

"Just watch."

$ cat one
When things look tough
you can always rely on
$ cat two
cat to concatenate files
and print them out
$ cat one two | grep on
you can always rely on
cat to concatenate files

You brush some pipe cleaners out of your eyes (you've been storing some extra in your hair), and try to figure out what's going on here. "Cat combines the files and prints them to standard output, but what does grep on do? And what is that suspicious pipe-looking thing?"

"You don't have to put your search for grep into quotes, so grep on just searches for anything containing 'on'. Only if you want spaces or other specific searches do you need quotes."

You nod, balancing pipe cleaners on the back of your hands. They're everywhere, but you haven't dropped any because you're cool like that.

"That suspicious pipe-looking thing is exactly what it seems like. It's the fabled unix pipe. A tool passed down for generations -- or, at least one generation -- and one of my favorite things. What do you think it does?"

You try not to sneeze with pipe cleaners up your nose. "Sensei, it looks like it set the file grep was using to the output of cat."

Sensei Tim blinked in surprise, "That's almost exactly right, actually. If you're being technical, that's how it works under the hood depending on the implementation, but we're going to take a step back and take a more abstract look at it."

He hands you another pipe cleaner.

"The terminology you're looking for is that cat printed standard output and grep accepted standard input. If grep doesn't get a file as its second argument, it looks for standard input by default. Most programs can accept standard input one way or another, which means that most programs can be piped together to form more complicated processes."

You're vibrating with excitement. Not enough to drop the pipes, but enough to make them shake like a Christmas tree with a cat stuck in it.

$ ls
banana.png cool.png one tim.mp3 timothy.mp4 two
$ ls | grep png
banana.png
cool.png

"Of course!" You yell, making Tim jump three feet in the air, "Because ls does standard output, grep can filter it using standard input! But Sensei... ls looks like it prints on one line, why doesn't grep print the whole line of files when it finds a match? Isn't it supposed to print the whole line when it finds a match?"

He hands you several more pipe cleaners. "That's because ls is a weird bastard child of commands. It's the most common command, but you do not at all use it for something serious. Repeat after me: 'I will not use ls for anything serious. I will only use ls when there is literally no chance of me destroying my files or causing other changes to anything on my system. I will never use ls in a script.' Say it now, before it's too late."

"I will not use ls for anything serious-" he hands you a pipe cleaner, "I will only use ls when there is literally no chance of me destroying my files or causing other changes-" another pipe cleaner, "to anything on my system. I will never use ls in a script..."

"Good," he says, "We're okay with this use case, since it doesn't cause any effects on our files, and isn't in a script. This is one of the few cases where using ls in a pipeline won't cause our future AI overlords to rain hell-fire upon us."

"Sensei, if I were doing something serious, what would I use instead?" You ask, pipe cleaners in your mouth wobbling.

"You would use the find command. And no, you won't be learning about that until you're older. I must preserve some of your innocence for as long as I can."

You nod sagely and say, "You're so wise Sensei."

"Hell yeah I am! Here's some more examples."

$ cat one two | grep t
When things look tough
cat to concatenate files
and print them out
$ cat one two | grep t | grep c
cat to concatenate files

"You can chain as many pipes together as you can manage before getting physically ill. I've personally committed atrocities well over 15 pipes long on my adventures, and I presume you will too one day. Notice how the line 'you can always rely on' doesn't appear in this output, because we filtered it out with the first grep before sending it to the second one that searched for 'c'."

You jump to your feet and yell, "Amazing!", launching pipe cleaners everywhere, and the Sensei has to clean up the mess. Jerk.

How to learn

"Sensei, please tech me more commands."

Sensei Tim was busy eating a whip made entirely of gummy worm material. It wasn't a gummy worm, just made of the same material. There's a difference. "Huh? I'm busy eating a whip made of gummy worm material. It isn't a gummy worm, just made of the same material. There's a difference."

No eccentric thing Sensei does phases you any more. You've become numb. "Sensei. I feel as if I have the frame work needed to produce great works, but lack the materials. Please teach me more commands!"

Sensei Tim, uses the remaining bit of gummy whip to flip the light switch on, throwing the entire room into relief for the first time since you've arrived. The stadium light embedded into the ceiling burns your skin.

You refuse to crack. You have a mission to learn, no matter how absurd Sensei Tim decides to be, "Sensei. I don't know how to do even the most basic things. I can't edit a text file easily, I can't rename files, I can't move files, I can't do anything! I don't even know what text editor I ought to use! I need guidance!"

Sensei Tim stops walking on the ceiling (with heat protectant gravity shoes) long enough to listen, sigh, do a quadruple back flip, and sit down at his famous teaching beanbag chair. "Come here, my apprentice. I will teach you the most important lesson I have."

Your retinas are burning, "Can we turn off the light?"

Your Sensei tries to whip the light switch back off, but he's eaten too much of the whip at this point and it can't reach, "Guess not. Sit down before I change my mind."

"I could turn it off if-"

"Hurry up, damn it!"

You sit down hurriedly. "What will I be learning today?"

"Are you familiar with this?" He types something into his laptop, waits for about 10 seconds, types something into it, and a mysterious website called "Google" appears on the screen.

"Gooo-guuul," you slowly pronounce, "What is this mysterious power, Sensei? Why are we not in the command line?"

"I thought- What?! Are you fucking serious? You don't know what Google is? Were you raised under a boulder in the middle of the sun?"

"I've heard the name, Sensei, but I've never used it before myself." you say truthfully.

"What... What did you even do on your old Windows machine?" He says.

"It's not important, Sensei," you say.

"I beg to differ!" He says.

"How do I use this Google, Sensei?"

"You're trolling me. I knew it. This whole thing is all just one big joke. You're not this incompetent. You have to know what Google is."

You say nothing.

"You know what? Fuck it. Fuck it all," he straightens up, "I'll teach you anyways, you ungrateful rat. Google is a website that allows you to search for other websites on the internet. You type what you want to know into this little box, and then a list of web links appear related to what you searched for."

"But what about the demons?" You ask.

"What."

"The demons. In my village research was illegal because the elders said demons would come out. You were supposed to only talk to an expert and take up their valuable time. Will we be fighting demons?" You look around, realizing that having the lights on for this was probably a good idea.

Tim, the legendary Sensei of the sacred art of the command line, the One of Plain Text, master of Nothing, Emperor of the Shell, puts down his laptop, gets up, walks to a far corner of the room, crouches into his knees, and screams for a solid minute straight.

He's probably just releasing the demons.

When your Sensei returns from his ritual sacrifice (at least, that's what it looked like), there's tears in his eyes and he's lethargic and irritable.

"Thank you, Sensei," you say.

"Huh?"

"Thank you for ridding us of the demons, just then."

"I- you-" He sighs, "You're welcome. You will forever be free of the... demons. It's part of training under one of the masters."

You thank him again for the privilege, and then wait eagerly for your lesson in this Google thing.

"Okay. Open up Google and type in what you want to know."

"But what do I type?"

"What you want to know."

You type in, How do I rename a file?, and are shocked to see links about renaming files. Except... "Sensei, all of these links are for Windows."

The Sensei nods, "That's right. Most people look for information for the more popular Operating System, so that's the first results. You need to give it more context for what your searching for, since Linux and the command line are much more obscure."

You try again, this time with How do I rename a file in Linux?, and find that literally the first link has your answer.

"So I use the mv command... But what's all this other stuff? I don't understand what else they're explaining."

"That's fine. You don't need to understand everything at once," says the Sensei, "You can use Google again to search for something you're confused about, if you need to. Although your basic question of how to rename files has already been solved."

You open up a new tab and search for, How do I edit text in Linux?. There's a lot of angry people this time. "There's so many text editors..." You say. "Which one should I use, Sensei?"

"Use whichever one you find most useful. There are people out there who are more efficient with Sublime Text than the best experts on Vim, for example. The trick is to try them all out, pick the one you like most, and then master it completely. Everyone else who says otherwise is just trying to pull you into a religion."

You think about this for a while, than ask, "What one do you use?"

"Vim, obviously. But let's focus back on the lesson at hand. Do you understand why Google searching is the most important thing I will teach you?"

"No..." you say, "Is it because the demons are gone?"

"What? No. It's because Google makes me obsolete. You know how to find information about anything you want to know, now. Once you get used to searching things online, you probably won't even have to ask me questions unless you become confused in a way that's hard to search for."

"But why didn't you just show me this first?" You ask, amazed.

"Because you need to understand the reasoning behind why it's important. The command line is enormous and complex, and to teach you everything myself would be far too complicated a task. What I've done is give you the bare minimum introduction, so that you know what context to search for. Your secret goal, this whole time, was to get to a level where you could kinda understand the results you get from searches."

"So you're telling me that every question I could possible have already has an answer somewhere on Google?" you say.

"With the right amount of effort, probably. You're just starting out, so you won't have a very high change of coming across a problem that hasn't been explained 100 different ways already." He says.

"Can't you just give me the answers?" you say.

"I could, yeah. But like I said, it's easier for both of us if you do your own research first. That way I know you're actually trying, and you know how to ask me most effectively. It takes a lot of practice in putting the puzzle pieces of advice online together into something coherent, but you can do it."

"And it's all free?"

"Yes. Although you could also buy a book if you want."

"But it's easier to ask someone for advice! My problems are unique!"

"They are unique, most likely. But I personally think it's easier to get an instant answer from Google than there is to wait an arbitrary amount of time from someone else. Even unique problems have general solutions, most of the time."

You sit there, Google loaded on your web browser, and realize you have been taught the secret to doing literally anything. The power of the universe expands before your eyes. Anything you want to learn, available at your finger tips, without having to deal with people!

"What a great gift you've given me, Sensei. I will use this to my full advantage at once."

The Sensei laughs once, "No you won't. You will come across something without a perfect solution and feel trapped, and then you will ask me for help, and then I will have to show you how to search for that solution. It is inevitable."

You stand up, cutting your foot on a spike of solidified gummy whip. "I promise, Sensei! I will dance you the dance of my village that binds a promise forever, just to prove it to you!"

You start to dance in a small circle, spilling blood from your cut foot onto the carpet.

"Wait. What are you doing?" says Tim.

"Dancing!"

"No, I mean what are you drawing with that blood?!"

You look down too late to realize that you've drawn a summoning circle and released the demons into the mortal realm, and the Sensei had to clean it up. Jerk.

Post script

My dear apprentice,

I hope this letter receives you well. After you released the scourge of the apocalypse onto us mortals, I've been too busy to catch up. Thanks for that, by the way. Hundreds of millions are dead.

I hope your adventures in the command line are going well. If they aren't, than I'm sorry for leading you astray. You will always be my favorite, and only, apprentice.

Personally, I've decided to hide out somewhere in the mountains and wait out the end of days. I have my laptop, and the demons keep the internet alive for some reason, so it's okay.

If you're looking for some other places to start, Here's a list of commands that I recommend you look into. In alphabetical order:

apropos
awk
basename
bash / zsh / fish
cat
cd
chmod
chroot
clear
curl
date
dd
df
diff
dirname
dmenu
du
echo
exit
fg / jobs / &
find
fzf
git
glob
grep
head
history
less / more / most
ls
make
man
mkdir
mv
patch
pgrep / pkill
pipes (|)
redirection (<, >, and so on)
rm
sed
sh
shuf
sort
sudo
tail
tar
time
tmux
top / htop
touch
tr
wc
whatis
whereis
xargs

These are some of the more useful and common commands that I use. Some are more complex than others, so just look around and find the ones you can understand right now.

Make sure to use your power of internet searching to learn everything you want to learn. It really is the best road to powerful computer usage.

Good luck, jackass,

-Tim