How to create a directory with permissions in Linux

The other day I was reading through some newsgroups on how to better automate a script.  Part of the script contained an interesting command that looked promising; however, could not get it work.

This is the command.

mkdir icinga:icinga 0700 mydirectory

While it looks interesting, a quick execution of it created three directories, icinga:icinga, 0700, and mydirectory. This was not the desired effect.

Looking through the man pages for mkdir, there is a switch for the mode. From that switch I modified the command to include the -m switch. Knowing that this will fail since there is no switch for the user and group.

mkdir icinga:icinga -m 0700 mydirectory

The result was the creation of icinga:icinga and mydirectory with mydirectory having 0700 for permissions.

If using the mkdir command, then other commands like chown will need to be used.

mkdir -m 0777 mydirectory
chown -R icinga. mydirectory

This leads to the command install. This command will accomplish everything in one line.

install -d -o icinga -g icinga -m 0700 mydirectory

Source(s)
http://serverfault.com/questions/647805/how-to-set-up-icinga2-remote-client-without-using-cli-wizard
http://unix.stackexchange.com/questions/73978/using-root-to-mkdir-in-another-users-home-directory