Sample Header Ad - 728x90

"> $logfile" does not truncate, file size goes to 0 and a second later, is back to full size

0 votes
0 answers
697 views
I have a script that writes to a logfile like this: $ nohup myscript.sh > myscript.out 2>&1 & when the log file gets very large, I need to truncate it like this: > myscript.out I see the size go to 0 briefly but immediately jumps back to full size again. $ ls -ald myscript.out -rw-rw-r-- 1 vmware vmware 14285855 Apr 11 04:33 myscript.out $ > myscript.out $ ls -ald myscript.out -rw-rw-r-- 1 vmware vmware 0 Apr 11 04:33 myscript.out $ ls -ald myscript.out -rw-rw-r-- 1 vmware vmware 14298778 Apr 11 04:33 myscript.out How can I truncate it so the size goes to zero and starts growing again from zero? I have tried many other alternatives but nothing works. Same thing, size goes to 0, then back to full size. true > myscript.out : > myscript.out echo -n > myscript.out cp /dev/null myscript.out truncate -s 0 myscript.out dd if=/dev/null of=myscript.out
Asked by chiwal (1 rep)
Apr 11, 2022, 09:41 AM
Last activity: Apr 11, 2022, 09:50 AM