which one is the best way to clean or empty a file in Linux? I have to zip ( tar ) a file to an archive and then clean/empty it; this is what I do and it works correctly:
tar -zcvf /mnt/file.tar.gz /mnt/file.txt > /dev/null 2>&1
echo "" > /mnt/file.txt
I'm doing it with echo, probably there is a better way ?
Thanks
There are multiple ways to do that:
We presume that our file is called access.log and it's in the current directory:
1.
: > access.log
2.
true > access.log
3.
cat /dev/null > access.log
4.
cp /dev/null access.log
5.
dd if=/dev/null of=access.log
6.
echo -n "" > access.log
7.
echo -n > access.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With