6

The following is often used to set file permissions, a good example being setting a key file to an appropriate permission level to be used by ssh (this being the "octal" form):

chmod 600 filename.xyz

Would it be a correct equivalent and acceptable practice to use the following instead (this is the "symbolic" form)?

chmod a=,u=r filename.xyz

The reason I ask is that it seems a bit clearer for code readability. Still not exactly human readable, but no bit mapping needed.

If maximum readibility (and not terseness) were the primary driver, would there be a better option?

4
  • Wow, I just realized that I used 400 instead of 600. 400 would be write only, which would not work for the ssh scenario that I mentioned. Jun 24, 2019 at 18:14
  • Heh, not sure whether it's irony... I made the mistake in the question that I was trying to solve via the same question. :-) Jun 24, 2019 at 18:16
  • Updated to change 400 to 600. Jun 24, 2019 at 18:16
  • 1
    I like chmod a=,u=r filename.xyz it is easy to read.
    – guettli
    Apr 27, 2023 at 11:18

1 Answer 1

6

With a=,u=r, the order is important. If you accidentally swap the order of a= and u=r (or the order of a= and u=), the result would be very different. (Yes, a and u are pretty far from each other on a QWERTY keyboard, but someone looking at a reference doc and manually typing things in might mess up between the two very similar looking parts.) For maximum readability and safety, I'd be more explicit:

chmod u=r,go-rwx filename # or go-rwxst

The permission components are very different here, and way more explicit, making mistakes less likely to happen. And it doesn't matter if you have go-rwx first or u=r first.

0

You must log in to answer this question.

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