Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there anyway to change the permissions of a file in Linux without using the chmod command ?

share|improve this question
    
In case mouviciel's tagging isn't apparent enough, the "why" missing from this question is: because this is my homework assignment. –  blahdiblah Nov 4 '09 at 22:59
    
Technically it is a question whose answer can get me some brownie points. It seems that the overall consensus is that it can't be done. –  Manish Mathai Nov 4 '09 at 23:54
add comment

6 Answers

up vote 1 down vote accepted

Remember, with umask, the value is subtracted from 777. So if you want a file to have 777 permissions for example:

$ umask 000
$ cp oldfile newfile
$ rm oldfile
share|improve this answer
    
Have you tried this? It doesn't work for me. –  innaM Nov 4 '09 at 17:00
    
you could always touch a new file to create it with 777 permissions. Then cat oldfile > newfile. –  John T Nov 5 '09 at 13:36
add comment

You can do it automatically with the umask command. Other than that, I'm not sure I understand the question. How many ways do you need to change file permissions?

share|improve this answer
add comment

You can write your own program with same functionality:)

share|improve this answer
add comment

The obvious response to that question would be another question: WHY?

But for the sake of whatever, you could change your current umask, make a copy of the file, delete the file and finally rename the copy to match the original.

UPDATE:

Note that this will only work changing the current permissions to more restrictive ones. The other way does not seem to work.

share|improve this answer
    
Why? Perhaps the chmod command is locked down or removed for security reasons, to prevent users from changing file flags. (Not that I would insinuate anything by stating this.) –  Torben Gundtofte-Bruun Nov 4 '09 at 15:44
    
Its a homework question. Is this the correct sequence of commands ? umask 0777 (say) cp file file.bk rm file mv file.bk file –  Manish Mathai Nov 4 '09 at 15:44
    
a umuask of 0777 will make the file permissions 000. –  John T Nov 4 '09 at 15:45
add comment

I guess you could use what ever Filemanager is installed with your Desktop GUI, if there is one installed.

If you right click on a file or directory, there should be an entry like "Properties" or something like that. That should produce a window, where you can change the rights and see some other infos.

share|improve this answer
add comment

Any program is going to use the chmod() family of system calls (see man 2 chmod , section two is for system calls) that changes the permissions of a file. So that is the only practical way, you could in theory edit the partition directly if you are root, but that is kind of crazy.

When you use the cp command, you are creating another file -- you are copying it. So those umask examples are not changing the permissions on a file.

share|improve this answer
    
I wish i can convince my professor that it is not possible to do it without using chmod. –  Manish Mathai Nov 4 '09 at 23:53
    
It is possible, just crazy:) –  Kazimieras Aliulis Nov 5 '09 at 9:28
    
Manish: Well if he says the umask is the answer, show him the output of stat file1 and stat file2, and show him how the inodes are different, they are different files. So all you are really doing is creating another file with different permissions, that happens to have the same data. –  Kyle Brandt Nov 5 '09 at 12:40
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.