在 unix 中删除文件需要什么权限? [英] What permissions are needed to delete a file in unix?
问题描述
我目前有一个目录(udir),它对所有用户只有读写权限.该目录包含两个文件(file1 & file2)
I currently have a directory (udir), which has only read and write permissions for all users. This directory contains two files (file1 & file2)
我最初虽然只需要(在目录上)写访问权限才能通过 (rm udir/file1) 删除/删除文件,但 rm 命令会让我拒绝访问.当我设置读取、写入和执行权限时,rm 命令起作用.
I initially though that only write access was needed (on the directory) for me to be able to delete/remove a file via (rm udir/file1) but the rm command would give me access denied. when i set the permissions to read, write, and execute, the rm command works.
显然也需要执行权限,但为什么呢??
Obviously the execute access is needed as well but why??
我认为对目录的执行访问是能够使其成为工作目录并搜索其内容并访问子目录.
I thought the execute access on a directory was to be able to make it a working a directory and search its contents and access sub directories.
推荐答案
您实际上需要目录的 read
和 write
权限,而不是操作后的文件本身考虑到目录的权限影响.
You actually need read
and write
permissions on the directory, not on the file itself since the operation is done considering the permissions effects of directories.
可以在 此链接,其中在目录的特殊注意事项部分中提到了以下内容:
A good documentation can be found on this link, which mentions the below in the section Special Considerations on Directories:
删除一个文件需要两个write(修改目录本身)并在目录上执行(到 stat() 文件的 inode).注意一个用户不需要文件的权限,也不需要文件的所有者来删除它!
To delete a file requires both write (to modify the directory itself) and execute (to stat() the file's inode) on a directory. Note a user needs no permissions on a file nor be the file's owner to delete it!
这篇关于在 unix 中删除文件需要什么权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!