5

I read everything about chmod, but I don't get something. If I write chmod u=rwx file this "affects" me for all rights on the file, and if I write chmod u+rwx file this "adds" me all the rights on the file, but what is the difference between + and =?

12

Since you're specifying all the read, write and execute bits, there's no difference.

The difference comes if you only specify some of the bits:

$ umask 022
$ touch afile ; ls -l afile
-rw-r--r-- 1 jackman jackman 0 Aug 21 11:23 afile
$ chmod u+x afile; ls -l afile
-rwxr--r-- 1 jackman jackman 0 Aug 21 11:23 afile*
$ chmod u=x afile; ls -l afile
---xr--r-- 1 jackman jackman 0 Aug 21 11:23 afile*
3
  • ok now I get it thank you very much to you and dagrha – Valkas Ironhorn Aug 21 '15 at 15:30
  • 6
    Actually, there is a difference. The setuid bit, if set, will be unset. – muru Aug 21 '15 at 15:38
  • Good example, could you please directly explain the difference in your answer? While it may be obvious to you, this would benefit future readers. – kiri Aug 22 '15 at 6:15
8

from the man pages:

The operator + causes the selected file mode bits to be added to the existing file mode bits of each file; - causes them to be removed; and = causes them to be added and causes unmentioned bits to be removed except that a directory's unmentioned set user and group ID bits are not affected.

1
  • This is the best answer, it directly answers the question. – hytromo Aug 21 '15 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.