What does chmod -u do?

This is not an option, but a standard (but uncommon) way of specifying the permissions. It means to remove (-) the permissions associated with the file owner (u), for all users (no preceding u, g, or o). This is documented in the man page.

GNU chmod's man page documents this as:

The format of a symbolic mode is [ugoa...][[-+=][perms...]...], where perms is either zero or more letters from the set rwxXst, or a single letter from the set ugo

and later

Instead of one or more of these letters, you can specify exactly one of the letters ugo: the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the file's group (g), and the permissions granted to users that are in neither of the two preceding categories (o)

So -u means to remove (-) whatever permissions are currently enabled for the owner (u) for everybody (equivalently to a-u, except honouring the current umask). While that's not often going to be very useful, the analogous chmod +u will sometimes be, to copy the permissions from the owner to others when operating recursively, for example.


It's also documented in POSIX, but more obscurely defined: the permission specification is broadly who[+-=]perms (or a number), and the effect of those are further specified:

The permcopy symbols u, g, and o shall represent the current permissions associated with the user, group, and other parts of the file mode bits, respectively. For the remainder of this section, perm refers to the non-terminals perm and permcopy in the grammar.

and then

-

... If who is not specified, the file mode bits represented by perm for the owner, group, and other permissions, except for those with corresponding bits in the file mode creation mask of the invoking process, shall be cleared.


The answer is little bit similar to https://unix.stackexchange.com/a/429424/255251.

chmod -u file_name

doesn't removes all permission, but it consider umask value.

umask
0022
ls -l file
-rwxrwxrwx 1 user user 4 Feb 25 15:17 file
chmod -u file
chmod: file: new permissions are ----w--w-, not ---------
ls -l file
-----w--w- 1 user user 4 Feb 25 15:17 file

Now change umask value

umask 777
chmod 777 file
chmod -u file
chmod: file: new permissions are rwxrwxrwx, not ---------
ls -l file
-rwxrwxrwx 1 user user 4 Feb 25 15:17 file