Create a directory dir1
• Create a file file1 in dir1
• Go to home directory
• Remove owner write permission permission for dir1
• Go to dir1
• Remove file1
Explain your observation?
Note: If you don't have write permission for a directory, then you can't delete a file in the directory. If you have write access to the file you can update the data in the file.
First we perform the following steps:
1. Create a directory dir1
2. Create a file called file1 in dir1
3. Go back to home directory
4. Remove owner's write permission permission for dir1
5. Go inside to dir1
Now when we try to remove the file1 we will get the error as follows:
rm: cannot remove 'file1': Permission denied
The reason is as follows:
Although you still have the write property of file file1, deleting it means you are making changes to the directory dir1 it resides in, not the file itself. This is because a file is just an inode, and the directory refers to that inode. By removing it, you are just removing a reference to that file's inode in the directory. So the owner is changing the directory dir1 and not the file file1, hence the error.
Get Answers For Free
Most questions answered within 1 hours.