DEV Community

Ibrahim
Ibrahim

Posted on

Create Nested Directories Recursively in Linux

To create a new directory in Linux, you can use the mkdir command.

mkdir projects
ls
# projects
Enter fullscreen mode Exit fullscreen mode

To create a new directory recursively in linux, add the -p or --parents option to the mkdir command.

mkdir -p projects/web/my-web-app
ls
# projects
ls projects
# web
ls projects/web
# my-web-app
Enter fullscreen mode Exit fullscreen mode

Using this method, you can create a new directory along with all necessary parent directories in a single mkdir command.

The -p or --parents option means that if any of the parent directories do not exist, they will be created automatically without throwing any errors.

Top comments (0)