I have this file:

$ ls -lrta ~/.bash_profile
-rwxr-x---. 1 xxx xxx 904 May 23 15:36 /home/xxx/.bash_profile

I am the owner of the file and I have write permission. When I try to edit (delete the last line for example) the file I got an error,

$ sed -i '$ d' .bash_profile
sed: cannot rename ./sedxkZezg: Operation not permitted

Appending a text using cat can successfully write to file.

$ cat >> .bash_profile

I viewed the appended text like this,

$ cat .bash_profile
... <some text> ...

Error also occurs when I edit the file using a text editor (vi).

Can anyone explain why can't I write the file though I have a write permission?

Here is some information of the system I'm using:

$ uname -svr
Linux 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012


Here is what I have tried so far:

$ 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
  • Any log about it? – Stéphane Chazelas May 23 '13 at 9:38
  • Sorry, I have no root access so I can't provide some logs right now. – e19293001 May 23 '13 at 10:05
sed -i ... file

actually does something like:

sed ... file > some-temp-file &&
  mv some-temp-file file

That last mv does a rename. That is sed -i doesn't edit the file in place, it replaces it with a modified copy of itself.

Here it's the rename that is blocked. It is not blocked because of permission issues (you'd get a permission denied error message if it was), but it looks like there's some administrative restriction either to unlink the inode of your ~/.bash_profile (like some SELinux type of mandatory access control), or to the path to that file (like some AppArmor type MAC).

You can probably find more clue somewhere in the logs.

getfattr -dm- ~/.bash_profile

would list all the extended attributes (ACLs, security contexts) of the file.

lsattr ~/.bash_profile

for potentially more Linux attributes.


The '.' at the end of the ls permissions output says there are extended data of some kind. chattr(1) gives the list of attributes for ext? file systems, lsattr(1) lists the current ones. Also check tha ACL for the file (getfacl(1)). A security policy (like SELinux) could also forbid some operations on the file.


Probably you dont have write permission of parent dir (which is weird because its your home)

Anyway, can you do:

$ ls -la ~
  • 3
    If he didn't, sed wouldn't have been able to create the ./sedxkZezg file. And the error would be EACCESS, not EPERM. Sounds more like some SELinux issue. – Stéphane Chazelas May 23 '13 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.