Creating a Linux Directory with mkdir

To create an empty directory called testdirectory within your current directory, use this command:

You can create a directory in a different location by changing what is after mkdir. To create a new directory in /home/hadi/music, if you are already in you /home directory, you can use the following:

Or from anywhere using an absolute path, you can use this:

Or from anywhere using a path shortcut, you can use the following command:

The -p option is valuable. It enables you to create a directory and its parent directories at the same time, if they do not already exist. This can be a real time saver. If the parent directories exist, the command works normally. For example, suppose you want to a new directory with two layers of subdirectories. In this example, music and testdirectory already exist, but subdir1 and subdir2 are to be created:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s