Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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).

Thanks!

share|improve this question
add comment

2 Answers 2

You can use the symbols o for others such as:

chmod o+rwx file

,

chmod o-rwx file

or

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
2  
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
2  
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
add comment

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):

#!/bin/bash

otherperm=$1
filename=$2

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
add comment

Your Answer

 
discard

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.