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
Benchmark disk performance using
In order to get a meaningful result run the test a couple of times.
Direct read (without cache):
And here's a cached read:
purposes. For meaningful results, this operation should be repeated
2-3 times on an otherwise inactive system (no other active processes)
with at least a couple of megabytes of free memory. This displays
the speed of reading through the buffer cache to the disk without
any prior caching of data. This measurement is an indication of how
fast the drive can sustain sequential data reads under Linux, without
any filesystem overhead. To ensure accurate measurements, the
buffer cache is flushed during the processing of -t using the
BLKFLSBUF ioctl.
For meaningful results, this operation should be repeated 2-3
times on an otherwise inactive system (no other active processes)
with at least a couple of megabytes of free memory. This displays
the speed of reading directly from the Linux buffer cache without
disk access. This measurement is essentially an indication of the
throughput of the processor, cache, and memory of the system under
test.
You can use
These are some useful and simple disk benchmarking tools.
#linux #benchmark #hdd #dd #hard_disk #hdparm
hdparm
& dd
.In order to get a meaningful result run the test a couple of times.
Direct read (without cache):
$ sudo hdparm -t /dev/sda2
/dev/sda2:
Timing buffered disk reads: 302 MB in 3.00 seconds = 100.58 MB/sec
And here's a cached read:
$ sudo hdparm -T /dev/sda2
/dev/sda2:
Timing cached reads: 4636 MB in 2.00 seconds = 2318.89 MB/sec
-t:
Perform timings of device reads for benchmark and comparisonpurposes. For meaningful results, this operation should be repeated
2-3 times on an otherwise inactive system (no other active processes)
with at least a couple of megabytes of free memory. This displays
the speed of reading through the buffer cache to the disk without
any prior caching of data. This measurement is an indication of how
fast the drive can sustain sequential data reads under Linux, without
any filesystem overhead. To ensure accurate measurements, the
buffer cache is flushed during the processing of -t using the
BLKFLSBUF ioctl.
-T:
Perform timings of cache reads for benchmark and comparison purposes.For meaningful results, this operation should be repeated 2-3
times on an otherwise inactive system (no other active processes)
with at least a couple of megabytes of free memory. This displays
the speed of reading directly from the Linux buffer cache without
disk access. This measurement is essentially an indication of the
throughput of the processor, cache, and memory of the system under
test.
You can use
dd
command to test your hard disk too:$ time sh -c "dd if=/dev/zero of=ddfile bs=8k count=250000 && sync"; rm ddfile
rm ddfile
removes the test file created by dd
command of=ddfile
. of
param stands for output file.These are some useful and simple disk benchmarking tools.
#linux #benchmark #hdd #dd #hard_disk #hdparm