Linux mkdir command examples

As its name implies, the Linux mkdir ("make directory") command lets you create new directories.

Creating a new directory in your current directory is very simple. In our first mkdir example, we'll show how to create a new directory named "dir1":

mkdir dir1

If you want to create several directories at one time you can use a mkdir command like this:

mkdir dir1 dir2 dir3

If you want to create a new directory named "dir2" in the "/tmp" directory while you're not in the "/tmp" directory you can do it like this:

mkdir /tmp/dir2

Creating multiple subdirectory levels at one time

The mkdir command only has a few options, and the one I use most frequently (-p) lets me create several directory levels at one time, like this mkdir example:

mkdir -p level1/level2/level3

That's a lot better than having to do this:

mkdir level1
cd level1
mkdir level2
cd level2
mkdir level3

Related links

 

Post new comment

The content of this field is kept private and will not be shown publicly.