0

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?

1
  • maybe the log file is locked/in use by mysql, try killing the mysql process first.
    – LastCoder
    Oct 15, 2012 at 16:04

1 Answer 1

4

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"

Or:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .