12.2.2. Making Directories
To create a directory, type the following (note that the first letter in a directory name indicates its action):
mkdir -p /home/boris/games/Hearthstone/bat icsk.html
This command creates the directory `/home/boris/games/Hearthstone/bat` if it does not already exist.
The -p option indicates that the user should create the directory even if it does not exist.
A shorter way to create a directory and ensure it is created is to use the mkdir command with the -p option:
There are several problems with the above command.
* If there is an existing directory at the specified path, it will be overwritten.
* If there is already a directory at the specified path and it is a subdirectory, it will be overwritten.
* If there is already a directory at the specified path and it is a file, a new file will be created, which will be a new version of the existing file.
* The user is not informed about all of these problems.
To work around the problems mentioned above, we can use the -p flag. We may also need to ensure that the user has execute permission on a directory.
Let's see how we can change our example to work with the -p flag. If we modify the original example to look like this, it will work as expected.
The -p flag requires the path to be absolute. We could also use a relative path and then be sure the user has read permissions. For example, we could create the directory in the users home directory, so we would use the following:
mkdir -p $HOME/games/Hearthstone/bat icsk.html
This would be a relative path.
When we use the -p flag, the following problems can occur:
* The directory is created in the current directory, not in the specified path.
* The directory is created in the user
Related links:
Comments