Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to recursively create folders using a shell script?

Tags:

linux

bash

shell

I'm trying to recursively create levels of directories like /folder1/folder2/folder3

I'm trying mkdir folder1/folder2/folder3, but it doesn't work. How can I do it?

like image 954
ulima69 Avatar asked Nov 25 '11 22:11

ulima69


People also ask

How do I create a recursive folder?

The -p option is used to create multiple child directories with mkdir command in a recursive manner. In order to create directories recursively non of the specified directories should exist because all of them are created automatically.

How do I create a folder in Shell?

The procedure is as follows: Open the terminal application in Linux. The mkdir command is is used to create new directories or folders. Say you need to create a folder name dir1 in Linux, type: mkdir dir1.

What is a recursive folder?

Alternatively referred to as recursive, recurse is a term used to describe the procedure capable of being repeated. For example, when listing files in a Windows command prompt, you can use the dir /s command to recursively list all files in the current directory and any subdirectories.

Does mkdir create subdirectories?

Creation of an entire directory tree can be accomplished with the mkdir command, which (as its name suggests) is used to make directories. The -p option tells mkdir to create not only a subdirectory but also any of its parent directories that do not already exist.


1 Answers

You should pass the -p parameter to mkdir so it will create all the subfolders. So following your example:

mkdir -p folder1/folder2/folder3 
like image 124
0xd Avatar answered Oct 03 '22 14:10

0xd