TubeSum ← Transcribe a video

Command Line Basics for Beginners — Step-by-Step Guide & Transcript

0h 45m video Published Jun 30, 2026 Transcribed Aug 10, 2026 F freeCodeCamp.org
Beginner 23 min read For: Complete beginners with no prior command line experience, such as aspiring developers, data analysts, or anyone looking to build essential technical skills.
AI Trust Score 70/100
⚠️ Average / Some Fluff

"Delivers a solid beginner course on command line basics, though the 'full course' title is slightly ambitious as it only covers section one."

AI Summary

This beginner-friendly course introduces the command line interface (CLI) and essential terminal commands through a hands-on project: building a geography quiz game. The instructor, Aby Boval, guides learners through file navigation, creation, deletion, and reading/writing files, using a narrative of organizing a startup's files. The course covers core commands like pwd, ls, cd, touch, rm, mkdir, rmdir, echo, and cat, with practical challenges to reinforce learning.

[00:01]
Course Introduction and Project Setup

The course is designed for beginners to learn terminal basics, bash commands, and essential CLI skills. The instructor sets up a project: a geography quiz game, and the learner is tasked with organizing files as an 'unpaid intern'.

[03:09]
What is the Command Line?

The command line is a text-based user interface to interact with the operating system. It's known by different names (Terminal on macOS, PowerShell on Windows) but serves the same purpose. The course will use the term 'terminal'.

[05:45]
Why Use the Command Line?

Three key reasons: 1) Faster and more efficient file management, 2) Essential for controlling development environments (installing packages, version control with git), 3) Excellent for automating repetitive tasks (e.g., adding a dot to 10,000 files).

[09:36]
First Commands: pwd, ls, cd

pwd (print working directory) shows current location. ls (list) shows contents of the current directory. cd (change directory) navigates to a specified directory. These are the foundational commands for navigation.

[14:35]
Navigation Rules and the Dot-Dot Syntax

Navigation in the file tree is like an ant walking on a tree: you must go via common parent directories. The '..' syntax allows moving one level up. For example, 'cd ../countries' from 'forests' goes up to the parent and then into 'countries'.

[20:47]
Creating and Deleting Files

Use 'touch' to create a file and 'rm' to delete a file. These commands operate in the current directory by default, but can be used with paths to target other locations (e.g., 'touch ../cities/biggest_cities.txt').

[25:27]
Creating and Deleting Directories

Use 'mkdir' to create a directory and 'rmdir' to delete an empty directory. For non-empty directories, use 'rm -r'. Trying 'rmdir' on a non-empty directory results in an error, which is a signal to use 'rm -r'.

[30:26]
Writing to Files with echo

The 'echo' command prints a string to the terminal. To write to a file, use the redirection operator '>' (e.g., 'echo hello world > hello.txt'). This overwrites existing content. To append, use '>>'.

[37:31]
Reading Files with cat

The 'cat' command (short for concatenate) prints the contents of a file to the terminal. Its output can also be redirected, e.g., 'cat hello.txt > hello_copy.txt' copies the file content.

[43:34]
Section One Recap

The instructor summarizes what was learned: navigation (pwd, ls, cd, ..), file creation/deletion (touch, rm), directory creation/deletion (mkdir, rmdir, rm -r), writing (echo), reading (cat), and redirection operators (> and >>).

This course provides a solid foundation in command line basics, using a practical project to teach essential file management skills. By the end of section one, learners are comfortable with core commands and ready to advance to more complex topics in section two.

Mentioned in this Video

Tutorial Checklist

1 09:36 Open a terminal in the Scrimba IDE by clicking the plus icon next to 'runner' and selecting 'add terminal'.
2 09:50 Use 'pwd' to print the current working directory.
3 10:35 Use 'ls' to list the contents of the current directory.
4 11:18 Use 'cd geography_game' to navigate into the 'geography_game' directory.
5 12:04 Use 'ls' to list the contents of the new directory.
6 12:20 Use 'clear' to clear the terminal.
7 14:35 Use 'cd ..' to go one level up in the file tree.
8 20:47 Use 'touch filename.txt' to create a new file.
9 21:00 Use 'rm filename.txt' to delete a file.
10 25:27 Use 'mkdir directory_name' to create a new directory.
11 26:04 Use 'rmdir directory_name' to delete an empty directory, or 'rm -r directory_name' for non-empty ones.
12 30:26 Use 'echo "string" > file.txt' to write to a file, or '>>' to append.
13 37:31 Use 'cat file.txt' to read the contents of a file.

Study Flashcards (11)

What does 'pwd' stand for and what does it do?

easy Click to reveal answer

Print Working Directory; it prints the current directory path.

10:07

What is the purpose of the 'ls' command?

easy Click to reveal answer

It lists the contents of the current directory.

10:35

How do you navigate to a subdirectory named 'geography_game'?

easy Click to reveal answer

Use the command 'cd geography_game'.

11:18

What does the '..' syntax do in a path?

medium Click to reveal answer

It means 'go one level up' in the file tree.

15:35

What command is used to create a new file?

easy Click to reveal answer

The 'touch' command.

20:47

What command is used to delete a file?

easy Click to reveal answer

The 'rm' command.

21:00

What is the difference between 'rmdir' and 'rm -r'?

medium Click to reveal answer

'rmdir' only works on empty directories, while 'rm -r' can delete non-empty directories.

26:18

How do you write a string to a file, overwriting existing content?

medium Click to reveal answer

Use the redirection operator: 'echo "string" > file.txt'.

31:38

How do you append a string to a file without overwriting?

medium Click to reveal answer

Use the append redirection operator: 'echo "string" >> file.txt'.

33:19

What command reads the contents of a file?

easy Click to reveal answer

The 'cat' command.

37:31

What is the 'cat' command short for?

easy Click to reveal answer

Concatenate.

37:31

💡 Key Takeaways

💡

Three Reasons to Prefer CLI

Provides a clear justification for learning the command line, addressing a common beginner question.

05:45
⚖️

File Tree Navigation as an Ant

Uses a memorable analogy to explain the rule of navigating via parent directories.

14:35
📊

rmdir vs rm -r

Clarifies a common point of confusion: when to use which command for deleting directories.

26:18
📊

Redirection Operator Overwrites

Highlights a critical behavior of the '>' operator that can lead to data loss if not understood.

31:38
🔧

cat Command Mnemonic

Offers a creative mnemonic to remember the 'cat' command, making it easier for beginners to recall.

37:31

[00:01] beginners, you'll learn terminal basics, bash commands, and essential CLI skills used by developers, DevOps engineers, and data analysts. The command line is a

[00:13] textbased interface that lets you interact directly with your computer's operating system. It's important for all developers to understand. IO from developers to understand. IO from Scribba created this course.

[00:29] basics course. My name is Io and you and I are going to work closely together on a project of mine. You see, I have this pretty amazing startup idea. I'm going to create a new video game and I am absolutely convinced that this game will

[00:45] be the next big thing. It's going to be a quiz game all about geography with questions like what is the world's tallest mountain or how long is the tallest mountain or how long is the river Nile? I mean the video game market

[01:00] has never seen anything like this before. It is going to be the next Minecraft or Candy Crush. I assure you. So I sat down the other day and started brainstorming on postits and I was literally so excited about this that I

[01:14] literally so excited about this that I kept going all night. But unfortunately, when I finally left the office at 5:00 in the morning, things did not look quite as organized as they do on this photo here. I knew I should have been

[01:26] more careful with the color coordination of my postits. But never mind. This is where you come into the picture, cuz I want to offer you an unpaid internship in my startup. Honestly, this is a great opportunity for you. Probably a once in

[01:41] a lifetime, I would say. Are you in? Well, great. Let's go. In order to set my own creativity free, I need a personal assistant who can keep track of all my million-doll ideas. I started doing this myself, but as you can see

[01:57] here, I'm really not caught out for this type of work, and I'm afraid I already made a bit of a mess of the file system. So basically what I need you to do is to finish what I have started and get everything entered into our system and

[02:11] sorted correctly into folders and files. To show you just how happy I am to have you on board, I will personally make sure you get solid training so that you feel equipped for the job. In other words, I will be your boss, your mentor,

[02:27] and last but not least, your biggest fan, cheering you on throughout the course. My name is Ay Boval and my pronouns are they them. I am a former Scribba student and graduated from the Scribba front end developer career path

[02:42] and from the Scriber teacher talent program. When I am not producing coding courses, I work as an IT engineer in Denmark. Feel free to reach out to me on LinkedIn. I am always happy to connect with students. Okay, are you ready for

[02:56] with students. Okay, are you ready for this? Let's get started. Before we can start working on our geography game, we need to take a second to talk about the tool that we'll use in this course, namely the command line.

[03:09] From my own experience, I know that the command line does feel a bit scary to work with when you're first getting started. The whole thing seems kind of mystical and that is why I chose to call this set of slides demystifying the

[03:22] command line. So, what exactly is the command line? Well, in short, the command line is a user interface that allows us to utilize the functions of our device. Depending on your operating system, the command line tool can have

[03:37] different names like the terminal on Mac OS or the PowerShell on Windows. But don't let you confuse by that. Essentially, these really are just different names for one and the same tool. Here on Scribba, the command line

[03:50] goes under the name terminal. And throughout this course, I will therefore use the word terminal to refer to our command line. As the name suggests, the command line is all about commands. We type a certain command in the terminal

[04:04] to perform a certain action in the operating system. We can compare this to the graphical user interface that every single one of us use on a daily basis on both our laptops and our smartphones. Let me give you an example. The

[04:19] screenshot you see here is from the Finder app on my laptop. This app has a graphical user interface. And what that interface shows here on this screenshot is our geography game setup. There are small icons next to each single item,

[04:34] informing us whether the item in question is a file or a directory. This interface lets us open any of the files here by clicking them. And we can also click the directories to open them here inside the Finder app and see what they

[04:47] contain. The second screenshot here is from the terminal on my laptop. What you see here is the very same geography game, but there are no icons this time and no fancy nicel looking front end since this is a command line interface.

[05:03] All we get here is plain text, but the contents are the exact same as before. We have the same files and directories stored in the same parent directory. And from the terminal, we can still open these directories. we can read the

[05:17] contents of files and so on. Basically, the finder app and the terminal are two different tools with one and the same purpose. Kind of like the screwdriver and the power drill. At least to some extent, the screwdriver and the power

[05:31] drill can be used to solve the same tasks, but often one tool will arguably be a better choice than the other. This leads us to the question of why we would ever want to type commands now that we have that finder app with its nice

[05:45] graphical user interface that seems so much more userfriendly and that is a great and valid question. Actually, there are plenty of reasons to prefer the command line interface over the graphical user interface and I will

[05:58] highlight three of them here. When it comes to file management, the command line interface is a faster and more efficient tool than the graphical user interface. As developers, we use the command line to control our development

[06:12] environment. We can install packages and dependencies. We can create virtual environments. We can handle version control with git and so on. Finally, the command line is an excellent tool when it comes to automating repetitive tasks.

[06:26] Now just imagine for a second that I ask you to add a single dot at the end of 10,000 files. Would you rather click each and every one of these 10,000 files in the Finder app to open them and then scroll down to the end and manually add

[06:43] that dot or would you rather write a script that does this for you and execute the script from the CLI? I know very well what I would choose. In this command line basics course, our focus will be on file management and what

[06:58] exactly does that mean? Let me show you by giving you an overview of the course curriculum. We will be studying the file tree and learn how to navigate it. You'll learn how to create and delete files and directories. How to write to

[07:12] and read from files, how to copy, move, and rename files and directories, how to perform searches and replacements in our project, and how to count and organize the content of your files. And we'll be doing all of this in the Scribbath

[07:28] terminal. We'll cover the first three topics on this list in section one and the last three topics in section two of the course. Along the way, you'll get plenty of hands-on exercises. And my goal is that by the end of the course,

[07:41] the command line will no longer be a scary mystical thing that you don't want to have anywhere near you, but rather a tool that you feel confident using and exploring. Before we finish here, let's quickly jump into the editor and set up

[07:55] our first Scribba terminal. Down here at the bottom of the window, we click the small plus icon right next to the word runner. This opens up a console where we can now click add a terminal. Now you can see that the tab that we are

[08:10] focusing in the console right here is indeed called terminal. Inside this terminal, a path is printed here in blue. And what it says here is tilda/

[08:22] project slash and then some ID like combination of letters and numbers. This is the path to the directory that we are currently working in. I don't want to anything in the terminal now. We'll save

[08:36] that for the next scrim. I simply wanted to show you how to even get started. All right, I am so ready for this now. Are you? I sure hope so, cuz here we go. In this scrim, we'll start dipping our toes into the world of the terminal. And

[08:52] the first thing you'll learn is how to get a basic overview of files and directories. The Scrimbar graphical user interface has a sidebar that I have currently hidden by clicking this icon up here in the top right corner. And the

[09:06] are barely going to use it in this course at all. If we wanted to, we could of course use this sidebar to get an overview of all files and directories in our project, but in a command line course that will basically be cheating.

[09:21] So we are not going to do that. Instead, you'll learn your first three commands and use those in the terminal to find out what files and directories we have in our project. Let's open up a terminal and get started. The terminal is up and

[09:36] running and I'm also going to move it up here by simply dragging and dropping so that we have it open in the same way as a regular project file. Okay. So in the previous scrim we saw that there is some initial information about our

[09:50] whereabouts in the file tree available to us as soon as we add a new terminal and that is the file path that we see here. We can get this same information in a bit more detail by typing the command pwd. After pwd we hit enter and

[10:07] a new file path is printed to the terminal. What we see now is /home slash projects slash and then this combination of letters and numbers that I'm not even going to try to read aloud. This is by the way the root directory of our

[10:21] current project. pwd the command we're using here stands for print working directory and that is exactly what happens here. The command tells us where we are currently at by printing out our current position in the file tree.

[10:35] Although it is always a brilliant start to know where you are. The command pwd does not itself help us understand what our current working directory contains. To get that information, we need to use the command ls. ls stands for list. And

[10:50] what it does is simply that it lists the contents. And there we go. When we hit enter after typing ls, we now see the contents of our current working directory printed in the terminal. Clearly, we have three items here. A

[11:05] file called capitals.txt. We have a file called challenge.md and we have a directory called geography game. Now assuming that I managed to save at least night and that I now want you to finish

[11:18] inside the geography game directory as well. To check if that is the case, we can navigate into geography game and list the contents of that directory. To make the navigation, we type cd geography game. CD stands for change

[11:34] directory. And this command will take us to wherever we tell it to in the argument that we passed to it, like geography game. Here we hit enter again. And now nothing was printed to the terminal this time. But can we tell if

[11:48] the command worked anyway? Yes, we can because take a look. The path that is printed now has geography game as the last part of it. Meaning we successfully navigated from the root directory into geography game. Okay. So, what should we

[12:04] do now to view the content of geography game? Well, I'm not going to tell you that since that will be up to you to figure out. But before I give you your there is one last command I want to show you and that is clear. The clear command

[12:20] does pretty much what it says. It clears the terminal. Though, it's important to understand that it is only performing a clearance of visual clutter. No actions are actually stopped. All right, that was enough of me

[12:34] talking. Let's look at the challenge. In step one, I want you to print the current working directory. In step two, navigate into the directory geography game. Then in step three, list the content of geography game. And finally,

[12:49] step four, clear the terminal from visual clutter. As you can see, I basically want you to do more or less what I just did. Though to teach you a bit, I am now going to use that clear command to clear the terminal from

[13:02] everything we've typed so far because now you cannot just copy paste my code. Okay, good luck with this challenge. Give it your best shot and return to me to see my solution. So I hope that went well. Let's go

[13:15] through it together. I'm actually going to put my terminal I'm actually going to put my terminal back down here because this allows us to view the challenge and the terminal at the same time. In step one, we are to

[13:27] print the current working directory. We do that with pwd and hit enter. As we can see, we are in the root directory. This one with a name consisting of numbers and letters in some ID like combination. From here, we have to

[13:41] navigate into geography game. For that we use cd and then we type out the name of the directory that we want to navigate to. When we hit enter, we can tell that the file path is changing. So the blue file path printed down here now

[13:53] shows geography game. In step three, we want to list the content of geography game. We do that with ls and hit enter. And in here we see a readme.md file. We have a countries directory, a forest directory, and a file called

[14:08] rainforest.txt. Finally, in step four, our job is to clear the terminal. So, we simply type clear and hit enter. Excellent job solving this challenge. When you are ready to move on, I will see you in the

[14:20] ready to move on, I will see you in the next one. there are some rules of navigation that we must understand and obey to. We can of course go wherever we want, but we have to follow certain routes cuz if we

[14:35] don't, we simply won't get to our destination. The best way to illustrate this is by looking at an actual tree as a representation of our file tree. When we move around in this realworld tree, we are not birds and we are not monkeys

[14:50] either. Actually, we are much more like tiny tiny ants. This means that flying or jumping between branches is not possible. We must always walk the long possible. We must always walk the long way. in our specific project here. This

[15:05] implies that if we are inside the subdirectory forests and want to navigate to another subdirectory at the same level like countries here, we cannot just jump or fly that distance. Instead, we must go via the common

[15:20] parent directory geography game. First, we go one level up and then we go down again into a different directory. Fortunately, this does not have to be as tedious as it might sound because we do have a way to make such a journey from

[15:35] forest to countries in one single command. The way to do this is by using command. The way to do this is by using the dot dot syntax. Take a look at the example here. The two dots that you see at the beginning of the path means go

[15:47] one level up in the file tree, please. If we stop here after the two dots and don't add the slash and everything after it, we simply navigate to the parent directory relatively to our current position. By adding the slash after the

[16:02] dots, we are saying to the terminal, let me enter a new directory, please. And then after the slash, we add the name of the directory that we want to navigate to. This syntax works with several different commands, including cd and ls

[16:16] that you have already learned. Okay, let's go back into the editor so that you can try this out on your own. As I said in the course introduction, I might have made some mistakes here and there in our project and created some files in

[16:30] the wrong place. So, your job is now to locate these misplaced files. To make navigation skills, I want you to start out by finding your way into the directory forests. Once you have ensured that you are inside forest, move on to

[16:46] step two and start locating the files I have listed here. It is rainforest.txt, large countries by population.txt and capitals.txt.

[16:59] Finally, in step three, I want you to clear the terminal from visual clutter. One important note here before I leave you to it. Please make sure to use everything you have learned so far. That is the commands pwd, ls, cd, the dot dot

[17:15] syntax, and the clear command. All right, jump into the terminal and solve on the other side of the little ghost icon. So, how did that one go? I hope you managed to do this just fine. Let's go

[17:28] through it together. First, we want to navigate into the directory forests. But how exactly do we know the correct route to this directory? Well, we go step by step. We print our current directory and we can see that we are in the root.

[17:43] Next, we list the contents and in here we can see that we have no forests directory called geography game. So let's navigate into that one. Now we are inside geography game and we list the contents again. And in here we see

[17:58] forests. So we use cd to navigate into that subdirectory to be absolutely sure that things are working the way we want to. We run pwd again and we can see the full path starting with home and ending in forests. Now this is our new starting

[18:14] job now is to find the three files that are listed in the challenge. Now a wild guess would be that rainforest should live inside forests. So let's list the contents of forests. Whoops, there was

[18:26] no rainforest file here. But we do have another file, large countries by population. That was the second file listed up here. And you know, I just realized, sorry about that, that I accidentally called these three items A,

[18:40] that didn't cause any unnecessary confusion. But anyway, we managed to find one of our three files. But there was nothing else of interest in here. Let's try to use ls and the dot dot syntax to list the content of the parent

[18:55] directory of forests. And look at that. Here we have rainforest.txt. Excellent. That was the first one of the files I have listed here. So we just have one single file left. That file could be in countries or it could be in

[19:10] our root directory. Let's try this from inside forest. We use ls together with the dot dot syntax to list the content of the subdirectory countries. Here we

[19:22] had a file called large countries by area but no file called capitals. So now there really is only one option left. The file capitals.txt txt must be placed in the root directory. To get straight from forests and back into the root

[19:36] directory, we can use the command cd, then two dots to go one level up to the parent directory, which is geography game. And now we can do something clever. We can add a slash and then two dots again. This takes us one level

[19:51] further up in the file tree. If you look at the file path that is printed in blue here, you can see that forest is now gone and geography game is gone. So, we are back in the root directory. In here, we list the contents. And there we have

[20:07] it. Capitals.txt. I am really glad that we found this file, but I'm also rather ashamed that I accidentally placed it outside of our geography game. It is not even in our game directory. Whoopsies. We'll have to

[20:20] fix that later when we'll learn how to move files. Now, to finish this challenge, the last thing we have to do is to clear the terminal. So, we simply type clear and hit enter. Very well done working on and hopefully solving the

[20:34] entire challenge on your own. When you are ready to move on, I will see you in the next scrim. Now that we know how to find a way around in the existing file tree, it is time for us to level up our game and

[20:47] learn how to create new files and also how to delete files from our project. So, we need to learn some new commands. To create a file, we use the command to give the file. For instance, mountains.txt.

[21:00] To delete a file, we use the command rm, short for remove, followed by the name of the file that we want to delete. This is in fact all you need to know to get started with creation and deletion in the terminal. But I do have a couple of

[21:13] share with you. Both of these two new commands, touch and rm, they will by default do the thing whether it's creating or deleting in the current working directory. But just as we saw with the commands ls and cd, we can use

[21:28] paths to create or delete in a different directory. For instance, this expression directory. For instance, this expression here touch do/cities/ biggest cities.txt. This will create a new file called

[21:41] biggest cities.txt txt and place this file in the directory cities. The cities directory itself lives at the same level as our current directory and therefore we start with the two dots to go one level up to the common ancestor. All

[21:55] a new challenge. So, let's jump back into the editor. While you were out on a coffee break, my uncle dropped by the office. He said something about that he couldn't read because he forgot his reading glasses. So, he wanted to

[22:10] use my laptop. It seemed kind of urgent and I really wanted to help him. Though, now we have a mysterious new file in our project called virus.exe. And honestly, I blame my boomer uncle for this. So, your job in step one of

[22:25] the scrims challenge is to find and delete this virus.exe file. When you are absolutely sure that the virus is deleted and gone, move on to step two. Here we are back on track working on our geography game. Although we are still at

[22:39] a very early stage building out the categories for the game, I think we need a file where we can write down ideas for how to play the finished game because you just never know when the lightning of creativity strikes you, right? So

[22:51] your job is to create a new file called rules.txt. Don't forget to read the hint I have written out here. Now jump into the terminal and solve this challenge. Okay, I hope this went well. Let's go

[23:04] through it together. As I wrote in the hint, we should always start by checking our current position in the file tree. We do that with pwd. And from what is printed in the terminal below pwd, we can tell that we are in the root

[23:17] directory. Now, I happen to know exactly where this virus.exe file is. So, let me just take us there. I use the command cd to navigate into geography game and then further into countries. And in here, I list the contents using ls. And there we

[23:33] have it. virus.exe, the second of the two files in this directory. Now, our job is to delete this virus. We do that with the command rm followed by the name virus.exe. Now, the terminal does not provide us

[23:49] with any kind of user message to tell us how this went. So, to be sure that we actually managed to delete this file correctly, we must now list the contents of countries again. So, we type ls and hit enter. And as you can see, virus.exe

[24:04] is gone. And that is indeed great news for us. And we can move on to step two. Our job is now to create a new file called rules.txt. We create new files with the command touch. And then we type out the name that we want to give this

[24:17] file. But in this case, we must pay attention to where we are actually at in the file tree. What is our Chrome working directory? You see, we are still inside countries. But step two in the challenge specifically tells us to

[24:30] create this file in geography game. So after the command touch, we start out by after the command touch, we start out by typing dot do/ to create a relative file path going one level up in the file tree. After the slash, we type out

[24:43] We hit enter and just like with the remove command, we don't get a user message in the terminal telling us how this went. So let's list the contents of geography game. We can do that with ls dot dot to list the contents of the

[24:57] parent directory of our current working directory countries. And as you can see now we have five items here. We have a readme file. We have two directories countries and forests. Then we have a file called rainforest.txt.

[25:11] And finally we have this new rules.txt file. That was it for this scrim's challenge. Excellent job if you managed to complete it all on your own. In the delete directories. So when you're ready for that, I will see you there.

[25:27] Creating and deleting directories is very similar to creating and deleting files. The syntax is basically the same and we have the exact same options for using paths to perform the creation and deletion somewhere else than in the

[25:39] current working directory. Though there is one very important difference and that is that we need to use a different set of commands. Let's start with a quick recap here. As you know, we use the command touch to create files and

[25:52] the command touch to create files and the command rm to delete files. When working with directories, we create new ones with the command maked, which is short for make directory. And then, just as with files, we write out the name

[26:04] that we want to give to our new directory. To delete a directory, we use the command rmd dur short for remove directory. And again, we must of course specify which directory we want to delete by writing out its name. When it

[26:18] very important thing that you need to know and that is that the command rmder only works if the directory that you want to delete is empty. If you want to delete a directory that is not empty, you must use the command rm-r instead of

[26:35] rmd dur. Trying to use rmd on a directory that is not empty does not break anything. So don't worry about that. It simply causes an error saying something like the directory is not empty. And that is when you know that

[26:47] you should use RM-R instead. My uncle came by the office again. This is him, by the way. My uncle. He does look a bit worried on this photo, but not quite as worried as he should be, I would say, considering that he infected my laptop

[27:00] with a virus just yesterday. Though, in spite of this, I just couldn't say no today, especially since he mentioned having some really cute photos of me as a baby from a family vacation back in 1988. Sadly, my dear uncle here cannot

[27:16] be trusted with a laptop and a Wi-Fi connection, and it would seem that these family photos somehow ended up somewhere inside our geography game. So, in step one of this scrim's challenge, your job is to find and delete the directory

[27:30] family photos 1988. When you're done with that, move on to step two and that we can eventually move that misplaced capitals.txt txt file that is currently placed in the root directory. Cities should be a subdirectory of

[27:46] geography game. All right, give this one everything you've got and return to me to see my solution. So, I hope that went well. Let's go through this one together. We want to delete this directory called family photos 1988. But

[27:59] before we can do that, we have to first find it. Luckily for me, I already know exactly where it is. So, let me just tick us there. I use the command CD to navigate into geography game and then further into countries. And inside

[28:11] countries, I list the contents using ls. Here we have it, the directory family photos 1988. Now we can use the command rmd followed by the name of the directory that we want to delete. Family photos 1988. But hang on a minute, we

[28:25] got an error here. What does this say? rm colon e not empty colon directory not empty? Wait a minute. Wasn't there something about rmd and empty

[28:37] directories? Yes, there is indeed something about the combination of rmdur and non-mpt directories. This is the error that I warn you about in my slides. And what is going on here is that family photos 1988 is not empty and

[28:51] therefore we cannot use rmder to delete it. Instead, we must use rm-r. Let's try one more time. rm-r followed by family photos 1988. We hit enter and

[29:03] it looks like it went better this time. At least we didn't get an error. But we anything about how this went. So to ensure that the directory was actually deleted correctly, we must list the content using ls. And here we can see

[29:16] that all we have left inside countries is the file large countries by area.txt. The family photos directory is gone. Excellent. Before we move on to step because I think it's getting a bit cluttered with this error message and

[29:31] everything. Okay, that was nice. A clean slate to work on. Now, we want to create a new directory called cities. We create new directories with the command maker give the directory. But we must be careful here because currently we are

[29:45] still inside the directory countries and that is not where we want to create the cities directory. So to get things right here, we must start by navigating one level up in the file tree using the two dots. Then we can add the slash followed

[29:58] by the name cities. We hit enter. We don't get a user message. So to check how this worked, let's list the content of geography game using ls dot dot. And look, this looks good. Now we have six items inside geography game. One of them

[30:13] being the new directory cities that we just created. Excellent. You are indeed making great progress in this course. And when you feel ready to continue, I'll see you in the next scrim. In the next couple of scrims, we'll

[30:26] learn how we can use the terminal to write to and read from files. The most basic thing we can do when it comes to writing is to write a string in the terminal that is an also printed in the terminal right below where you typed it.

[30:40] To do that, we use the command echo followed by a string like hello world. here. What echo does is simply that it echoes or repeats what you just said and therefore the output of echo will always be the same as your input. Let's quickly

[30:55] jump back into the editor so that you can try this out on your own. In this mini challenge, I want you to write a greeting to yourself in the terminal following this pattern here. Hello, and then your name and finally an

[31:09] exclamation mark at the end. Make sure to wrap the string in single quotes just like I've done in the example. Okay, give this one a go. All right, I'm sure not going to walk you through this one actually as it was just a minute

[31:23] challenge. Let's instead return to the slides and continue learning about writing to files. If we want to take the string hello world and print it to a file instead of to the terminal, what we need to do is to redirect the output of

[31:38] echo. We can do this with what we call the redirection operator followed by the name of the file that we want to write to. The expression that you see here echo hello world redirection operator hello.txt will result in the string

[31:54] hello world being printed to the file hello.txt. the first part of the expression with the command echo and the string hello world is the exact same as before but now after the string we add the

[32:06] redirection operator and we then specify the file where we want the string printed finally it's important to note that echo can also create files for us that we run the same command as before with redirection and everything but the

[32:22] file hello.txt txt does not yet exist in our project. In this case, Echo will our project. In this case, Echo will create this new file for us. At the time of recording though, there is an issue in the Scriber IDE that causes this

[32:35] specific syntax here where we use echo to create the new file while writing to it to not always work as expected. So, just be aware that currently you have to first create the new file using touch and then write to it using echo. But

[32:50] this is normally not necessary. It's a temporary bug. When we redirect an output, all existing content in the file that we are redirecting to will be overwritten. So instead of just saying that this expression here, echo hello

[33:04] world redirection operator hello.txt, instead of saying that it redirects the output of echo to hello.txt, we could be more specific and say that it redirects and prints our output and at the same time overwrites existing content. To

[33:19] avoid overwriting and instead append the output to the existing content, we need to use a different operator, namely the append redirection operator. So we take the same character as before, the arrow head pointing to the right, but we make

[33:33] it a double this time instead of a single like in this example here where we say echo welcome back and then the append redirection operator followed by the file name. This results in the string welcome back being printed below

[33:47] hello world in the file hello.txt because we use the append redirection operator to append content instead of overwriting. Okay, it's time for you to put these new skills into practice. So let's get going

[34:01] with the main challenge of this scrim. In step one, I want you to create a new directory called about the game inside the geography game directory. Step two, the geography game directory. Step two, write the string ab CEO and creative

[34:15] genius. That is me, of course, abioval. Write the string to a new file called team members.txt. This file should be placed inside about the game. In step

[34:27] about yourself to this team members file. The string should be your own initials and then the phrase hardworking intern. Finally, in step four, I want you to open up this new file in the sidebar to check that everything went

[34:42] well. And the reason why I'm asking you to do this is because you have not yet learned how to read from files. So, the only way for you to check that your code is working is by actually opening the file and looking at its content. Now,

[34:54] you the best of luck, and I'll see you back here to show you my solution. this just fine. Let's go through it In step one, we want to create this new directory about the game. And whenever

[35:10] absolutely sure about a position because if we're not, we might end up creating directories or files in the wrong place. So, let's start with pwd. We are currently in the root directory. This is not where we want to create the new

[35:25] directory. So, let's navigate into geography game. Now that we are inside the correct directory, geography game, we can create the new directory about the game. We do this with make and the name we want to give the directory.

[35:38] Let's list the contents here to check that everything went well and it did. directory about the game inside geography game. I am going to navigate into that one as well. So I say cd about the game in here. This directory should

[35:52] be completely empty because we just created it. So what we want to do now is use touch to create the new file team members. So the full command is touch team members.txt. Let's list the contents of about the game. Here we can

[36:05] see that we successfully created the new file and now we can use echo to write to this file. So we start with echo. Then we open up our single quotes here. Type out the string and creative genius. Then we close our single quotes. We use

[36:20] the redirection operator and we type out the name of the file that we want to write to team members.txt. That was step two. On to step three. This is your time to shine. We use echo again to add a string about you to our team members

[36:34] file. So after echo, we open up our single quotes. And I unfortunately have to just type n as your initials because I'm terrible with names. Don't take it personally. It's a CEO thing. I have so much on my mind. Anyway, NN hardworking

[36:48] intern. We end the single quotes. And now we don't want to overwrite me, the organization from the team members file. So, we have to use the append redirection operator and then the name of the file again, team members.txt. So,

[37:03] now to the moment of truth. How did this go? We open up the sidebar, open up about the game. In here, we have our team members file. And look at that. This is the beginning of something great. Amazing job solving this

[37:17] challenge. If you are curious about what we should do to read from this file without opening it from this sidebar as we just did now, then just stick with me cuz in the next scrim, that's exactly what you'll learn to do. See you there.

[37:31] It is time for you to learn how to use the terminal to read from files. The command we need now is cat. This is short for concatenate. And I must admit that to me personally, it is quite difficult to understand the connection

[37:46] difficult to understand the connection between concatenating and reading. Maybe it makes perfect sense to you. I don't know. Maybe it's because English is not my first language. But no matter what, I came up with a pneummonic that helped me

[37:59] just help you as well. A bit of a personal question here. Are you a dog person or a cat person? I am more of a dog person myself. So, in my head, I swap the word cat with the word dog because you can actually train a dog to

[38:16] fetch things for you. Things like dog biscuits or maybe even the newspaper. A cat, on the other hand, is harder to train. But nothing's impossible. So, my point here is that the dog fetches the paper and lets you read it. And with a

[38:31] bit of luck, the cat might just hit the right keys on your keyboard. For instance, the cat command and let you read from your files. Brilliant, right? No. Anyway, this expression here, cat

[38:44] Anyway, this expression here, cat hello.txt, magically typed by your cat on your laptop keyboard, this prints hello world, the content of the file hello.txt to the terminal. Just as we saw with echo, we can redirect the

[38:58] output of cat as well. The expression you see here, cat hello.txt you see here, cat hello.txt redirection operator hello.txt txt reads the content of hello.txt which we know is hello world and then writes it to the

[39:13] file hello copy.txt. Now nothing will be printed in the terminal anymore. Everything goes straight from one file to another. And again just as with the echo command, cat will create the file hello copy.txt for

[39:28] us if it does not already exist. One last thing, remember that the redirection operator overwrites all existing content and that you should use the append redirection operator to avoid overwriting. Okay, let's get going with

[39:41] a challenge so that you can practice everything you have learned. While you were off somewhere else taking a well-deserved break, I created a new file in our project called external people.txt where I listed a few people I

[39:53] know that might be able to help us with the geography game. But then afterwards, external? Why not just bring them straight onto the team? So that will be your job. Now in step one, you should find this file external people.txt and

[40:08] print its contents to the terminal to see what it is. Step two, read the contents of external people.txt again, but this time redirect and append it to team members.txt. Step three, print the contents of team

[40:23] members.txt to the terminal to check that everything went well. And finally, in step four, delete external people.txt. Cuz now that we have added don't want to have this information living in two different files. All

[40:37] right, give this one a go. So, I hope this went well. Let's get to work. First of all, we need to locate the file external people.txt. I know exactly where it is. Let me show you. I use the command cd to navigate into geography

[40:52] game and then further into cities. And in here a list of contents and there we have it external people.txt. We want to read the contents of this file. So we use the command cat followed by the name of the file that we want to read from.

[41:06] We hit enter and the content is printed to the terminal. We have three lines of text here. So three people each with their own expertise and responsibilities ready to be brought straight onto our team. We want to read the contents

[41:20] again. So we start with the same expression cat external people.x txt. This time the content should be redirected and appended to a new file. So we of course use the append redirection operator. Finally, we need

[41:32] to specify where we want to send this content to. The file is called team members.txt. But that's not the whole story because team members.txt lives inside the directory about the game which is a subdirectory of geography

[41:46] game, meaning it is on the same level as cities. So to get there, we need to tree and then down again into about the game and then we can access team

[41:58] members. So the expression as a whole is now cat external people.xt append redirection operator and then dot dot/about the game/team members.txt. We

[42:10] hit enter and as always we don't get a user message here. So, what we need to do to find out how this went is to read the contents of team members. To avoid typing the entire file path for team members again, I'm actually going to

[42:24] navigate into about the game. List the contents to be sure that we are in the correct place. We see team members.txt here. And now we read from this file. Moment of truth. Let's hit enter. And there we have it. I mean, look at this

[42:38] team. We have me, of course, at the top of the file, the most important person, the CEO. and then four different hardworking people. This is truly a dream team. Okay, but before I get too carried away about this dream team,

[42:52] let's finish the challenge by deleting external people.txt. To delete a file, we use the command rm. And this time, since we're now in about the game, we again have to make this relative file path where we go up one

[43:05] level into geography game and then down again into cities. And in here, we can access external people. So we say rm do/cities/external people.txt. Finally, we have to be sure that we did successfully delete this

[43:20] file. And the way to prove this is by listing the contents of the directory cities. Look at that. It's empty. The file is gone. We made it. Very well done solving this challenge. I will see you in the next scrim.

[43:34] Congratulations. You officially made it to the end of section one of this command line basics course. I always believed in you and knew that you can do it and so did this cute and cheerful animal. As your boss, I am very happy

[43:47] and impressed with everything that you put into our geography game project. Your hard work makes a difference every single day. Therefore, I am so pleased to announce that you are once again employee of the month. You should be

[44:00] very proud of yourself and let me tell you why. During this first section of the course, you have accomplished a lot. First of all, you took a great leap of faith when deciding not to be scared of the terminal and instead embrace this

[44:14] non-graphical user interface and learn how to use it. You have learned how to navigate the file tree using the commands pwd, ls, and cd and the dot dot syntax. You now know how to create files and directories using the commands touch

[44:29] and make dur. You also know how to delete files and directories with the delete files and directories with the commands rm, rmd dur, and rm-r. You master both writing to files using echo and reading from files using cat.

[44:45] And last, but certainly not least, you know everything there is to know about redirecting and appending with these two operators here, the redirection operator and the append redirection operator. At the time of recording this scrim,

[44:58] section two of this course is still in the making, and I really hope that you about the command line when we launch it. In the meantime, make sure to celebrate your victories and to give your brain some rest before diving into

[45:12] your next coding project. I'll see you around in the Scriber community. Now, around in the Scriber community. Now, keep up the good work and happy coding.

More from freeCodeCamp.org

View all

⚡ Saved you 0h 45m reading this? Transcribe any YouTube video for free — no signup needed.