After mkdir command options '-m '

Hi everyone,

I dont understand what is the mean of ''-m 777' after mkdir command?

example:

mkdir -p /mnt/nestor -m 777
mkdir -p /mnt/usb/sda1 -m 777

Hello,

The -m flag is used to set the mode (or, to put it another way, the permissions) that will be set on the directory when it is created. By default, when you create a file or directory, it will be created with whatever the currently-set umask specifies is the default set of permissions. If you want your directory created with different permissions, you use this flag.

For example:

$ mkdir test1 -m 0700
$ ls -ld test1
drwx------ 2 unixforum unixforum 4096 May 12 18:28 test1
$

Here, we created a directory called test1, with permissions of 0700 - which equates to read, write and execute for the owner, and nothing at all for anyone else.

Another example:

$ mkdir test2 -m 0711 
$ ls -ld test2
drwx--x--x 2 unixforum unixforum 4096 May 12 18:29 test2
$

Here, we created test2 with permissions of 0711 - so the owner has full read, write and execute permissions, and everyone else only has execute permissions (which in the context of a directory, lets them enter the directory and access its contents, but only by name - they can't list the contents of the directory, but can access things that are there if they know what they're called).

Hope this helps ! If you have any further questions, please let us know and we can take things from there.

The correct order is "options first".

mkdir -p -m 777 /mnt/nestor /mnt/usb/sda1

Thanks everyone, yours answers was more than enought.