I recently had a bunch of entries in my btmp log [because of a boneheaded move on my part] I resolved the issue, but now I would like to clear that log, I copied it somewhere else for reference and then I attempted to null the file, but to no avail. I then checked the permissions for the file itself and everything looks right? Just unsure of why it will not let sudo access the file.

user@localhost:~$ sudo cat /dev/null > /var/log/btmp
-bash: /var/log/btmp: Permission denied
user@localhost:~$ ls -a -l /var/log/btmp
-rw-rw---- 1 root utmp 5502336 Aug 20 18:59 /var/log/btmp

Just looking for some other ideas.. I tried changing the permissions and then changing them back just because. I also tried a few other ways to remove the text. But I want to figure out why this doesn't just work. Thanks for any help!


Your command does not use sudo to write to the log file - it (unnecessarily) uses sudo to cat /dev/null. The writing (output redirection) via the > operator is still done as your regular user.

You can do either of the following

sudo sh -c 'cat /dev/null > /var/log/btmp'


cat /dev/null | sudo tee /var/log/btmp

however there's really no need to cat anything; you can truncate the file equally well simply by redirecting nothing to it

sudo -i
> /var/log/btmp

or by using the truncate command

sudo truncate -s0 /var/log/btmp 
  • Thank you for the amazing response! I went ahead and ran: sudo truncate -s0 /var/log/btmp Worked just as you explained. Would you mind explaining the -s0 switch? I presume that is what sets it to blank? Thanks again! – Jasper Aug 21 '14 at 1:16

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.