Creating and Navigating to a New Directory
Now that you understand how to check your current location, let's learn how to create a new directory and navigate to it. These operations use the mkdir (make directory) and cd (change directory) commands.
Creating a New Directory
To create a new directory, use the mkdir command followed by the directory name. Let's create a directory called strategy:
mkdir ~/project/strategy
In this command:
mkdir is the command to create a directory
~/project/strategy is the path where we want to create the directory
~ is a shortcut that represents your home directory (/home/labex)
After running this command, no output is displayed, which is normal for Linux commands that complete successfully.
Navigating to the New Directory
Now that we have created the strategy directory, let's navigate to it using the cd command:
cd ~/project/strategy
Again, there's no output when the command completes successfully. But how do we verify that we've actually changed directories? This is where our pwd command from Step 1 becomes useful:
pwd
The output should now show:
/home/labex/project/strategy
This confirms that we have successfully navigated to the new directory. The path now includes strategy at the end, indicating that this is our current working directory.
Creating and navigating directories is a fundamental skill when working with the Linux file system. You'll use these commands frequently in your Linux journey.