Bash - Only mkdir if it does not exist - Stack Overflow

Mkdir invalid option

Mkdir invalid option


The -p (., parents ) option creates the specified intermediate directories for a new directory if they do not already exist. For example, it can be used to create the following directory structure:

MS-DOS and Windows command line md and mkdir commands

Moreover in the same command you can have two or more different way to call the same action.
So for another option with the same command you can do

Mkdir -- create a new directory

Thus, for example, the following command would create three directories within the current directory (., the directory in which the user is currently working) with the names dir_6 , dir_7 and dir_8 :

The mkdir Command - LINFO

It is very easy to confirm that this series of directories has been created by using the du (., disk usage ) command with the name of the first directory as an argument. In the case of the above example this would be

457399 – mkdir: invalid option -- 't' when installing the

In general the use of the space after the option depends from the command and the option that you intend to use. Each time you have to read the synopsis of the command. In this case you can use man mkdir.

If the option is written with a space you have to use the space between option and option_argument. If it is not present you have not to use it. You can see the standard links below for the complete list of rules and exceptions.

It is necessary for a user to have write permission (., permission from the system to create or change a file or directory) in the parent directory (., the directory in which the new directory is to be created) in order to be able to create a new directory.

If a directory name provided as an argument (., input) to mkdir is the same as that of an existing directory or file in the same directory in which the user is asking mkdir to create the new directory, mkdir will return a warning message such as mkdir: cannot create directory `dir_6': File exists and will not create a file with that name. However, it will then continue to create directories for any other names provided as arguments.

Directories created by mkdir automatically include two hidden directories, one representing the directory just created (and represented by a single dot) and the other representing its parent directory (and represented by two consecutive dots). This can be seen by using the ls (., list ) command with its -a option , which tells ls to show all directories and files, (including hidden ones) in any directory provided to it as an argument, or in the current directory if there are no arguments, .,

Thus, for example, to create a new directory named dir_5 for which the owner has read and write permissions, the group has read permission and other users have no permissions, the following would be used:


Leave a comment