Loading video player…

Create Two Directories (Solution)

00:00 Here I am again in my terminal. That’s what you see on the left side. And basically, I will be in the terminal for all the exercises. So I probably won’t mention it in future exercises, but this time on the right side, you also see my file explorer.

00:13 The reason why I’m doing this is that we are seeing live what changes I’m doing in the terminal. So we could check everything in the terminal with commands as well, but it’s nice to have it a bit more visual for this course.

00:26 The first thing we need to do is to navigate to the desktop to navigate in the file system in the terminal, you use the cd command.

00:37 cd stands for change directory, but the cd command alone doesn’t do anything because you need to tell the terminal where you want to go.

00:46 And now there is one cool shorthand on Unix systems where you can use the tilde character followed by a slash, and that’s basically your user directory. And when I want to go to desktop, I use the tilde slash and then desktop with the cd commands before that.

01:04 And once I press enter, I am going to the desktop.

01:09 How do I know if I’m on the desktop now? There is another command, pwd. pwd stands for print working directory. And that shows me the path.

01:21 So now we can be sure that we’re on the desktop. And the next part was to create a directory named pip_exercises. For this, I use mkdir, then a space pip_exercises.

01:40 And once I press enter, you see on the right side of the screen that there is a new folder named pip_ exercises in the file explorer.

01:48 So cool, that worked.

01:50 Now change into the newly created folder and print the current working directory. The command to print the current working directory you already know. And also, you basically know how to move into a folder.

02:03 So this should be nothing new to you, it’s cd. And then you use the folder name that you just created. And here I can use another trick and that’s starting with a name that exists in that folder.

02:16 And press tab. And then the terminal auto-completes if it finds something. So in this case, this pip_exercises folder exists, and once I cd in it, I can do pwd and that prints the current working directory, which now is the pip_exercises folder on the desktop.

02:37 To move back to the desktop, I can use cd. And now I could use the tilde desktop command, but I can also use .., which is the parent directory link.

02:47 Once I press enter and use pwd, you can see that I moved back to desktop. And from there, we should create another folder named other_ exercises.

03:02 Once I press enter, you can see on the right the folder got created. And with ls, I can list all the folders in the terminal as well.

03:11 This concludes this exercise.

Avatar image for ajackson54

ajackson54 on Sept. 8, 2024

Hello, Philipp. I don’t understand changing the directory to Desktop. When I entered ‘cd ~\Desktop’ my message was ‘Can not find path ‘c:\Users\Afj67\Desktop’ because it does not exist’. I tried a few things like This PC\ Desktop because This PC is a parent of Desktop. I ended up creating my two directories in my cwd(c:\Users\Afj67). Can you help me with my confusion?

Avatar image for Martin Breuss

Martin Breuss RP Team on Sept. 9, 2024

@ajackson54 hm… I think you should usually have a Desktop\ folder in your user home path, also on a Windows system 🤔

The ~ shortcut is usually on UNIX systems (like macOS and Linux) but as far as I know it also works on Windows, and from the output you shared it seems that your system correctly expanded the shortcut into the absolute path c:\Users\Afj67\Desktop.

So, I’m currently not sure what went wrong there. Can you use the user interface to navigate to your Desktop\ folder? Does it exist, or does it maybe have a custom name for some reason?

If you’re in your desktop folder, then check what its absolute path is. Is it the same as the one you tried to access?

Avatar image for ajackson54

ajackson54 on Sept. 12, 2024

Hello, Martin — this is where I’m getting confused. On my Windows I have three sections – Quick Access, One Drive- Personal, and This PC. As I understand it, This PC is the parent, and C: and Desktop are the children. C: and Desktop are siblings. Because of this, Desktop couldn’t be a child of c:\Users\Afj67. Is there something I’m not seeing, or is my logic totally wrong?

Avatar image for Martin Breuss

Martin Breuss RP Team on Sept. 13, 2024

Ah, I see. That must be just a representation to make your Desktop easy to find. I agree that “This PC” is what you want to look at, and it could potentially contain more than one disk. However, I think in your case there’s probably just one:

  • C: Drive: This is your main storage drive, and it’s the root of all other files and folders within your system.

  • Desktop Folder: The desktop folder is generally stored inside the path C:\Users\[YourUsername]\Desktop. This means your Desktop is a child folder of your user directory, located on the C: drive.

So the Desktop is indeed part of your user profile directory, which itself is stored on the C: drive:

- C: is a parent folder (root of the drive)
  - Users (folder)
    - Afj67 (your user profile)
      - Desktop (folder within your user profile)

In short:

  • C: is the root.
  • Desktop is indeed a child folder of C:\Users\Afj67.

When you see the Desktop next to your C: drive in “This PC”, then this is most likely just a quick link to make it easier to find.

I’m pretty sure that’s what’s going on. Were you able to get the absolute path to your Desktop? What does it read?

Avatar image for ajackson54

ajackson54 on Sept. 14, 2024

Hello, Martin. I found it. When I checked the absolute path to my Desktop I discovered that it was in the OneDrive folder( c:\Users\Afj67\OneDrive\Desktop). Seeing Desktop next to C: drive confused me. Thanks for all your help, Martin.

Avatar image for Martin Breuss

Martin Breuss RP Team on Sept. 16, 2024

Oh interesting, glad you found it and thanks for posting :)

Become a Member to join the conversation.