Introduction
In this lab, you will learn how to create a new directory and print current working directory.
Achievements
mkdir
- create a new directorypwd
- print current working directory
In this lab, you will learn how to create a new directory and print current working directory.
mkdir
- create a new directorypwd
- print current working directorypwd
is a command that prints the current working directory.
Just like ls
, pwd
is a command that is built into the shell. You don't need to install it separately.
pwd
don't take any arguments, so you can just type pwd
and press enter, then you will see the current working directory.
cd ~/project
pwd
Output:
/home/labex/project
If you use cd
to change the current working directory, then pwd
will print the new current working directory.
cd ~/Desktop
pwd
Output:
/home/labex/Desktop
mkdir
is a command that creates a new directory. It is short for "make directory".
Just like ls
and pwd
, mkdir
is a command that is built into the shell. You don't need to install it separately.
Be sure you are in the ~/project
directory before you run the following commands.
cd ~/project
To create a new directory, type mkdir
followed by the name of the new directory, then press enter.
mkdir new-directory
ls
Output:
new-directory
mkdir
can also take multiple arguments, which are the names of the new directories. You can type mkdir
and then the names of the new directories, then press enter, then you will see the new directories are created.
Be sure you are in the ~/project
directory before you run the following commands.
mkdir new-directory-1 new-directory-2
ls
Output:
new-directory-1 new-directory-2
mkdir
can also create nested directories.
Be sure you are in the ~/project
directory before you run the following commands.
mkdir new-directory-1/new-directory-3
ls new-directory-1
Output:
new-directory-3
mkdir
can also create multiple nested directories with parent directories. You need to use -p
option to create parent directories, otherwise you will receive an error.
Be sure you are in the ~/project
directory before you run the following commands.
mkdir -p new-directory-4/new-directory-5
ls new-directory-4
Output:
new-directory-5
Congratulations! You have completed the lab.
In this lab, you have learned how to create a new directory and print current working directory.
Keep learning!