Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 want to clear the content of /var/log/mysql/mysql.log. I tried this:

sudo cat /dev/null > /var/log/mysql/mysql.log

But it says I don't have permissions. That is strage for me because as you can see I'm running it as root.

Why can I not empty the content of mysql.log with that command? What is your advice to empty it?

share|improve this question

migrated from Oct 15 '12 at 21:34

This question came from our site for professional and enthusiast programmers.

maybe the log file is locked/in use by mysql, try killing the mysql process first. – LastCoder Oct 15 '12 at 16:04
up vote 4 down vote accepted

The > operator redirects the standard output from sudo (which is invoked with arguments cat /dev/null) and therefore you are attempting to write to the log file with your actual user privileges, not with elevated sudo privilege.

You must instead either:

sudo bash -c "cat /dev/null > /var/log/mysql/mysql.log"


cat /dev/null | sudo tee /var/log/mysql/mysql.log
share|improve this answer
That is the right answer. As in a pipe, your sudo privileges vanishes when you do a redirect. – shkschneider Oct 15 '12 at 16:12

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.