6

I was trying to remove some old history from my .bash_history file, but I was receiving this message:

[john ~] /home/john $ mv .bash_history .bas
mv: impossible to move `.bash_history' to `.bas': Operation not permited

I suspected the file/directory permission:

[john ~] /home/john $ ls -ld .bash_history .
drwxrwx--T+ 5 root       john 4096 Out 11 19:45 .
-rw-r--r--  1 john john 2977 Out 10 14:36 .bash_history
[john ~] /home/john $

Then I tried:

[john ~] /home/john $ lsattr .bash*
-----a------- .bash_history
------------- .bash_logout
------------- .bash_profile
------------- .bashrc
[john ~] /home/john $

Probably it is this a attribute; what does it mean?

1 Answer 1

13

The a attribute means that the file is append-only: you can't overwrite it or delete it, only append data to it. This is explained in the chattr man page. Only root can remove the attribute.

The practical consequence is that you can't erase your old history lines. This is presumably intended as a security measure by your system administrator. I'm not completely convinced it's secure, but off the top of my head I can't think of a way to remove some of the file's contents. (It is however easy to bypass the file and run commands without their showing in the history, which is why it's not a particularly useful security measure against competent users — an obvious way being to run the commands from something other than bash.).

1
  • Also, going through the history command and using the -d option may allow line deletion even with this setting in place
    – Jeter-work
    Nov 5, 2015 at 18:20

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.