-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [每日一题] 2019-11-14 - 删除文件是否需要对该文件具有写权限,为什么? (#61)
每日一题 - 删除文件是否需要对该文件具有写权限,为什么?
- Loading branch information
Showing
2 changed files
with
50 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## 每日一题 - 删除文件是否需要对该文件具有写权限,为什么? | ||
|
||
### 信息卡片 | ||
|
||
- 时间:2019-11-14 | ||
- tag:`OS` | ||
|
||
### 题目描述 | ||
|
||
删除文件是否需要对该文件具有写权限,为什么? | ||
|
||
### 参考答案 | ||
|
||
删除文件不需要该文件的写权限,需要文件所在目录的写权限以及执行权限。 | ||
|
||
因为删除文件修改的该文件父级即其所在目录的内容,所以需要目录的写权限。 | ||
同时,删除文件先要进入到目录,进入是目录的一个操作,所以需要该目录的执行操作。 | ||
|
||
##### bash 验证 | ||
|
||
```bash | ||
mkdir a && touch a/b #新建a目录,a下有b文件 | ||
chmod -w a && rm a/b #去掉a的写权限,尝试去删除a/b,报 rm: a/b: Permission denied,说明删除文件需要文件所在目录有写权限 | ||
chmod +w a && chmod -w a/b && rm a/b #恢复a写权限,去掉b写权限,尝试去删除b, 删除成功,说明删除文件不需要写权限 | ||
touch b && chmod -x a && rm a/b #去掉a的执行权限 报rm: a/b: Permission denied,说明删除文件需要目录的执行权限 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters