8

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 =?

2 Answers 2

15

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 Aug 21, 2015 at 15:30
  • 7
    Actually, there is a difference. The setuid bit, if set, will be unset.
    – muru
    Aug 21, 2015 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, 2015 at 6:15
10

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, 2015 at 22:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .