Chmod equivalence of +x and 0755

6

2

Just curious, are these two completely equivalent?

chmod +x file
chmod 0755 file

rluks

Posted 2012-03-25T13:06:06.363

Reputation: 399

2No, because +x just adds x to the current mask for everybody, not influencing rw, while 0755 changes the whole mask. – None – 2012-03-25T13:07:52.383

-1 You would have found this out if you read the man page for chmod and possibly the wpedia page for Filesystem permissions. – Eroen – 2012-04-19T15:55:09.867

Answers

7

chmod 0755 file is equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1). The 0 specifies default special modes (see comment below). See wikipedia for more info (including tables describing u,g,o,a and r,w,x,s,t,).

So in other words: No, they're not equivalent since 0755 contains more flags.

See also: chmod man page

keyser

Posted 2012-03-25T13:06:06.363

Reputation: 186

That's not accurate. The 0 specifies set UID (4), get GID (2) and sticky bit (1) in the first of the 4 numbers. If omitted, it assumes a padded 0 on the front. – None – 2012-03-25T13:12:50.217

@iandouglas But "if omitted, it assumes a padded 0 on the front", should then mean that 0 is the default? So in other words, you're just saying that it should say "no special special modes" ? – None – 2012-03-25T13:26:03.270

To my knowledge, yes, 0 is an implied default, so "755" should be the same as "0755" – None – 2012-03-25T13:54:17.657

@iandouglas post edited – None – 2012-03-25T13:57:44.563

6

Chmod number sets the permissions to exactly that number. Chmod relative only changes the requested bits. A file whose permissions were 000 before chmod +x will now be 111. Conversely, a file whose permissions were 0775 before (read+write+execute for owner and group; read and execute for others) will be unchanged by chmod +x, whereas setting the mode to exactly 0755 will change the 020 bit (remove write access for group).

tripleee

Posted 2012-03-25T13:06:06.363

Reputation: 2 480

3

No, because chmod 755 also sets various read and write flags.

Oliver Charlesworth

Posted 2012-03-25T13:06:06.363

Reputation: 972

0

No, they are not equivalent because chmod+x will set the file permission to execute for the current user and chmod 0755 will allow full permission to owner, read and execute permission for groups and for others. And regarding first digit here according to man page:

0 -> selects attributes for the set user ID (4) and set group ID (2) and save text image (1)S

akshat

Posted 2012-03-25T13:06:06.363

Reputation: 1

0

Assuming your file was already chmod 644, then, yes, they are effectively equal. It's better to explicitly list the bits you want to set though, using something like a+x

iandouglas

Posted 2012-03-25T13:06:06.363

Reputation: 109