I want to erase the contents of the file error.log (nginx error log file), but I don't want to actually delete the file.
is this possible?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
You can use this:
(typed just like that - an empty output redirection)
truncate -s0 error.log
sudotakes effect. Or you can do
sudo bash -c '>error.log'May 19, 2014 at 10:56
echo "some words" > output.txtbut nothing is going in. Oct 25, 2018 at 16:46
You'll confuse the daemon. Erase the file then send
SIGHUP to nginx.
truncateare atomic, so as long as no seeking is going on (especially if the only operation that's occurring is appending) it shouldn't be disruptive. Dec 4, 2010 at 3:25