If you want to erase all contents of a file then you can make use of the truncate command on the bash shell.
Usage:usage: truncate [-c] -s [+|-|%|/]size[K|k|M|m|G|g|T|t] file ...
truncate [-c] -r rfile file ..
Example 1:
truncate -s 0 data.txt
Another quick way to empty a file is by redirecting an empty string to the file.
Example 2:> data.txt

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!