Wednesday, 25 February 2015

How to delete Content of File in windows and unix?

Sometimes there are need to empty a file without opening the file. We can do the same with following two methods.

Method 1.
Delete the file and re-create the file with same name and extension.

Method 2.
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.txt
6. 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
touch filename.txt
truncate -s 0 filename.txt