Which is more widely used: chmod 777 or chmod a+rwx

Google gives:

  • 1,030,000 results for 'chmod 777'
  • 371,000 results for 'chmod a+rwx'

chmod 777 is about 3 times more popular.

That said, I prefer using long options in documentation and scripts, because they are self-documenting. If you are following up your instructions with "Run ls -l | grep file.txt and verify permissions", you may want to use chmod a+rwx because that's how ls will display the permissions.


[I edit to add best practice, following Dotancohen suggestion in his answer. I hope it doesn't make it less clear, and that the good habit is taken]

Important additional information: They are not equivalent.

chmod a+rwx : set the last 3 octals to 777, so it ensure that Owner, Group and Users have the "rwx" set. If there are additional bits in the first octal (setuid, setgid, and/or Sticky bit) it leaves them untouched. Think about it as a binary "or 00777".

chmod 777 : set the rights to 00777, so it ensure Owner, Group and Users have "rwx" set, AND NOTHING MORE. It also make sure the additional bits (setuid, setgid, and/or Sticky bit) are set to 0.

So use the first form, if you just want to make sure to grant access to everyone (and please make double, triple sure that it is required... it opens the door to all sort of security problems, some quite unexpectedly broad in what they allow a malicious user to do)

Use the 777 form if you also want to make sure to reset any setuid/setgid/sticky bit, ie if the files needs to be "00777", which is probably more likely in your case (the file's right is known, and should be : 00777). Here also, make triple sure that it is really needed...

Usually it's best to keep access to owner(and sometimes group) : then use the groups to grant access to some specific users to the file/directory. a+rwx is both easy and usually the wrong way to grant access (of course there are very rare cases when it is the only way...)

http://en.wikipedia.org/wiki/Chmod is a good read as it explains what each number or letter represents (including setuid/setgid/sticky)


I usually think of the difference being that setting the permissions to 0777 explicitly sets them to 0777. As mentioned earlier, the leading 0 will be inferred if you just type 777. Whereas a+rwx adds read/ write/ execute leaving the setuid/ sticky bit untouched.

Suppose you just want to be sure that a file is executeable, you might use a+x so that you can modify the execution privilege without worrying about or modifying the other permissions. If you used the octal representation, you would need to know what the permissions are currently set to to be sure that you do not modify the permissions in some other way besides what you intended.