【问题标题】:Why cannot root writes on a file that it owns and has write access to?为什么不能 root 写入它拥有并具有写入权限的文件?
【发布时间】:2021-06-21 07:25:34
【问题描述】:

我需要写入 a.txt。该文件由具有读写访问权限的 root 拥有。但我仍然不能用 sudo 写它。为什么?

% ls -l
total 8
-rw-r--r--  1 root  staff  6 Mar 24 00:30 a.txt

% sudo echo "hi" >> a.txt
zsh: permission denied: a.txt

【问题讨论】:

标签: linux file-permissions permission-denied


【解决方案1】:

重定向发生在命令运行之前,即使用原始用户。

解决方法:

sudo sh -c 'echo "hi" >> a.txt'

【讨论】:

    猜你喜欢
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    相关资源
    最近更新 更多