Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the mkdir -p mean in a script file?

Tags:

linux

shell

I have found a part of script like this In xx.sh:

BUILD_BOOT=.
mkdir -p $BUILD_BOOT

Can anybody help to explain what's the script above for as the directory parameter is .?

like image 597
user3011988 Avatar asked Nov 20 '13 07:11

user3011988


People also ask

What is meant by mkdir?

The mkdir (make directory) command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md .

What is mkdir in shell script?

The mkdir command in Linux/Unix allows users to create or make new directories. mkdir stands for “make directory.” With mkdir , you can also set permissions, create multiple directories (folders) at once, and much more.

What is mkdir command used for?

Use the mkdir command to create one or more directories specified by the Directory parameter. Each new directory contains the standard entries dot (.)

What does mkdir do in bash?

The mkdir command creates directories. This command can create multiple directories at once as well as set the permissions for the directories.


3 Answers

-p is short for --parents - it creates the entire directory tree up to the given directory.

E.g., suppose there are no directories in your current directory. If you execute:

mkdir a/b/c

It will fail, since you do not have an a subdirectory.

On the other hand

mkdir -p a/b/c

Will create the entire structure - a/b/c

like image 165
Mureinik Avatar answered Sep 19 '22 16:09

Mureinik


mkdir -p means: create the directory and, if required, all parent directories. The fact that this makes little sense when the path is specified as ., so the current working directory, does not change this. Most likely the line where the path is defined is meant to be adapted as required.

In general: consult the linux manual pages for questions about commands and their options like this: man mkdir. A great source of information!

like image 39
arkascha Avatar answered Sep 18 '22 16:09

arkascha


See mkdir.

It creates all the intermediate directories on the path to the final directory that do not already exist (as well as the final directory), and doesn't fail if the target directory already exists.

In context, it is pointless; if the BUILD_ROOT is the current directory, it already exists. At some time, the BUILD_ROOT must have been a longer path.

like image 34
Jonathan Leffler Avatar answered Sep 16 '22 16:09

Jonathan Leffler