Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use for example to change everyone's permissions:

chmod 777 file

Now, what if I want to preserve the current permissions?
I know there's something like

chmod xx7 file

in case I'd only want to change the world permissions, but I can't work it out (forgot).


share|improve this question

You can use the symbols o for others such as:

chmod o+rwx file


chmod o-rwx file


chmod o+r file

You can use - to revoke or + to grant the permission r, x , w, or any combination of them. Similarly, you can do this for user u or group g.

share|improve this answer
Thank! How with numbers? – Poni Jan 23 '12 at 8:40
I don't think can do this in numbers. What's wrong in using the letters? – Khaled Jan 23 '12 at 8:55
A bit cleaner that's all. I'll give this a day or two and if none comes up with a numeric solution I'll mark your answer. For now I just upvote :) Thanks again! – Poni Jan 23 '12 at 9:00
There is no "cleaner" solution. This is the solution. – adaptr Jan 23 '12 at 11:16
Also, I did not mention the = operator. This can be used to set the permissions such as o=rwx to give full-permission for other. – Khaled Jan 24 '12 at 8:59

Khaled's answer is best: learn to use symbols.

If you really want something to set permissions like you want, you can write some sort of script to get the octal format of the permissions, strip off the last digit and substitute your own.

I suppose you can write some sort of bash script like (note: untested and has no input validation):



newperm=`stat -c%a $filename  |sed -e "s/.$/$otherperm/"`

echo chmod ${newperm} ${filename}

but, really, learn to use symbols in chmod.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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