chmod -w john.c'. Then 'rm *' deletes john.c too!
Hi: Suppose I want to delete all files in a directory except one, john.c. What I did was to reset the write bit in the permissions, 'chmod -w john.c'. Then 'rm *'. But john.c got deleted too. Any way out of this?
|
did you rm * as john.c the user or what ever user has permissions to write to those files?
|
File owner can do this. It seems that you're the owner of the file.
So first change the ownership of the file, remove write permissions and then try to remove all other files. Code:
~$ chown user:group john.c |
Deleting john.c is possible because you hold write permissions on the directory. The proposal to change ownership of the file seems to be correct to me.
jlinkels |
Useful answers. They will be saved. Thanks.
|
Removing a file is an operation on the directory, so the directory permissions are what matters. If you have write permission in the directory, you can remove any file**. Write permission for the file is not required, but if you try to remove a file for which you do not have write permission, the rm command will, in the absence of the "-f" flag and if stdin is connected to a terminal, ask for confirmation before doing the removal. But that is really just a warning, and you do have the permission needed to remove the file.
**Directories with the "sticky" bit set in their permissions ("t" in the last character of the ASCII permissions) have an additional restriction. To remove a file from such a directory you must be the owner of the file or the owner of the directory. This bit is commonly set on publicly writeable directories like /tmp (perms "rwxrwxrwt"). |
It should stop and ask you before deleting the file.
Quote:
Quote:
|
All times are GMT -5. The time now is 01:50 PM. |