我有这个文件:
$ ls -lrta ~/.bash_profile
-rwxr-x---. 1 xxx xxx 904 May 23 15:36 /home/xxx/.bash_profile
$
Run Code Online (Sandbox Code Playgroud)
我是文件的所有者,我有写权限。当我尝试编辑(例如删除最后一行)文件时,出现错误,
$ sed -i '$ d' .bash_profile
sed: cannot rename ./sedxkZezg: Operation not permitted
$
Run Code Online (Sandbox Code Playgroud)
使用 cat 附加文本可以成功写入文件。
$ cat >> .bash_profile
writing
^D
$
Run Code Online (Sandbox Code Playgroud)
我像这样查看了附加的文本,
$ cat .bash_profile
... <some text> ...
writing
$
Run Code Online (Sandbox Code Playgroud)
当我使用文本编辑器 (vi) 编辑文件时,也会发生错误。
谁能解释为什么我不能写文件,尽管我有写权限?
以下是我正在使用的系统的一些信息:
$ uname -svr
Linux 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012
Run Code Online (Sandbox Code Playgroud)
更新:
这是我迄今为止尝试过的:
$ sed -i '$ d' .bash_profile > file && mv file .bash_profile
sed: cannot rename ./sedm89Ym2: Operation not permitted
$ lsattr ~/.bash_profile
lsattr: Inappropriate ioctl for device While reading flags on /home/xxx/.bash_profile
$ getfact ~/.bash_profile
getfacl: Removing leading '/' from absolute path names
# file: xxx/xxx/.bash_profile
# owner: xxx
# group: xxx
user::rwx
group::r-x
other::---
$
Run Code Online (Sandbox Code Playgroud)
可能您没有父目录的写权限(这很奇怪,因为它是您的家)
无论如何,你能做到吗:
$ ls -la ~
Run Code Online (Sandbox Code Playgroud)