Subject: bug#36503: bug in 'mkdir' (ver 8.26)

From: Bernhard Voelker <[email-masked]>
Date: Fri, 5 Jul 2019 16:19:56 +0200

tag 36503 notabug
close 36503
stop

On 7/4/19 6:31 PM, Sergey Koltsov wrote:
> Hello!
> I found a mismatch in the behavior of the program with its description.
> 
> When starting with *--mode=0700* and *--parents*, the rights apply only
> to the last created directory.
> The manual does not describe the exact behavior when specifying options.

Thanks for the bug report.

The detailed manual is not the man page:

   $ mkdir --help | grep ^Full
   Full documentation <https://www.gnu.org/software/coreutils/mkdir>

That texinfo manual shows:

   ‘-p’
   ‘--parents’

      Make any missing parent directories for each argument, setting
      their file permission bits to the umask modified by ‘u+wx’.
      Ignore existing parent directories, and do not change their
      file permission bits.

So I think mkdir is doing what it is supposed to do in your case, and
the documentation matches the behavior.

If you want to change the permissions of the intermediate directories,
then the manual also will help you:

   To set the file permission bits of any newly-created parent directories
   to a value that includes ‘u+wx’, you can set the umask before invoking mkdir.
   For example, if the shell command ‘(umask u=rwx,go=rx; mkdir -p P/Q)’ creates
   the parent P it sets the parent’s permission bits to ‘u=rwx,go=rx’.
   To set a parent’s special mode bits as well, you can invoke chmod after
   mkdir. [...]

For your case, this seems to be:

   $ ( umask go-rwx && mkdir --mode=0700 --parents --verbose ~/a/b/c/{1..6}; )
   mkdir: created directory '/home/berny/a'
   mkdir: created directory '/home/berny/a/b'
   mkdir: created directory '/home/berny/a/b/c'
   mkdir: created directory '/home/berny/a/b/c/1'
   mkdir: created directory '/home/berny/a/b/c/2'
   mkdir: created directory '/home/berny/a/b/c/3'
   mkdir: created directory '/home/berny/a/b/c/4'
   mkdir: created directory '/home/berny/a/b/c/5'
   mkdir: created directory '/home/berny/a/b/c/6'

   $ find a -exec ls -logd '{}' +
   drwx------ 3 4096 Jul  5 16:13 a
   drwx------ 3 4096 Jul  5 16:13 a/b
   drwx------ 8 4096 Jul  5 16:13 a/b/c
   drwx------ 2 4096 Jul  5 16:13 a/b/c/1
   drwx------ 2 4096 Jul  5 16:13 a/b/c/2
   drwx------ 2 4096 Jul  5 16:13 a/b/c/3
   drwx------ 2 4096 Jul  5 16:13 a/b/c/4
   drwx------ 2 4096 Jul  5 16:13 a/b/c/5
   drwx------ 2 4096 Jul  5 16:13 a/b/c/6

As such, I'm closing this ticket, but discussion can continue by
replying to this thread.

Have a nice day,
Berny