Create Directory and Print Path

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to create a new directory and print current working directory.

Achievements

  • mkdir - create a new directory
  • pwd - print current working directory

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/FileandDirectoryManagementGroup -.-> linux/pwd("`Directory Displaying`") linux/FileandDirectoryManagementGroup -.-> linux/mkdir("`Directory Creating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") subgraph Lab Skills linux/cd -.-> lab-270249{{"`Create Directory and Print Path`"}} linux/pwd -.-> lab-270249{{"`Create Directory and Print Path`"}} linux/mkdir -.-> lab-270249{{"`Create Directory and Print Path`"}} linux/ls -.-> lab-270249{{"`Create Directory and Print Path`"}} end

Print Working Directory

pwd 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

Create New Directory

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

Create Multiple Directories

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

Create Nested Directories

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

Create Multiple Nested Directories with Parent Directories

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

Summary

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!

Other Linux Tutorials you may like