Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
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.

share|improve this answer

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.

share|improve this answer

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

Anyway, can you do:

$ ls -la ~
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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