How to truncate a log file in
or
If you want to be more eloquent, will empty logfile (actually they will truncate it to zero size). If you want to know how long it "takes", you may use
(which is the same as
You can also use:
to be perfectly explicit or, if you don't want to
(applications usually do recreate a logfile if it doesn't exist already).
However, since logfiles are usually useful, you might want to compress and save a copy. While you could do that with your own script, it is a good idea to at least try using an existing working solution, in this case logrotate, which can do exactly that and is reasonably configurable.
#linux #sysadmin #truncate #dd #dev_null #logfile
Linux
:> logfile
or
cat /dev/null > logfile
If you want to be more eloquent, will empty logfile (actually they will truncate it to zero size). If you want to know how long it "takes", you may use
dd if=/dev/null of=logfile
(which is the same as
dd if=/dev/null > logfile
, by the way)You can also use:
truncate logfile --size 0
to be perfectly explicit or, if you don't want to
rm logfile
(applications usually do recreate a logfile if it doesn't exist already).
However, since logfiles are usually useful, you might want to compress and save a copy. While you could do that with your own script, it is a good idea to at least try using an existing working solution, in this case logrotate, which can do exactly that and is reasonably configurable.
#linux #sysadmin #truncate #dd #dev_null #logfile