Sometimes there are need to empty a file without opening the file. We can do the same with following two methods.
Delete the file and re-create the file with same name and extension.
Follow the simple steps.
1. Press window+R
2. Type the cmd and press enter key.
3. Now you are not window command prompt area.
4. Go to the same folder where file exits to delete the content.
5. Type the following command (replace the demo.txt with your file name)
copy /y nul demo.txt6. Now check its empty.
Question: How to delete the content of file in Unix?
Following are three different way, choose which suites to you.
cp /dev/null filename.txt
truncate -s 0 filename.txt