DbAppWeb.com

Menu
  • Home
  • Linux
  • HP-UX
  • macOS
  • Windows
  • Web Servers
  • App Servers
  • Storage

How to Clear the Contents of a File in Windows

August 19, 2020 DbAppWeb Admin

Sometimes, we need to clear the contents of a log file or text file which is continuously increasing in size to save the space on the hard disk. In Linux, we can easily do it and there are many commands to clear the content of the file to make the file empty. The most used command in Linux systems to clear the content of a file is cat /dev/null > filename.log

If we want to clear the content of log file /var/log/messages then we have to use the below command

# cat /dev/null > /var/log/messages

 

Clear the Contents of a File in Windows

In Window, we can clear the content of a text file or log file using the cat command and it really works

  • Search the Command Prompt and Run as administrator.01 How to Clear the Contents of a File in Windows
  • First, check the size of the file named logFile.log, here it is around 15 MB.
    C:\windows\system32>dir F:\logFile.log
     Volume in drive F is New Volume
     Volume Serial Number is 3446-545B
    
     Directory of F:\
    
    16-07-2018  14:52        15,803,465 logFile.log
                   1 File(s)     15,803,465 bytes
                   0 Dir(s)  71,806,472,192 bytes free</pre?

 

  • Run the command cat /dev/null > logFile.log to clear the contents of the file. It will give you an error but the contents of the file will be removed which we will verify in the next step.
    C:\windows\system32>cat /dev/null > F:\logFile.log
    'cat' is not recognized as an internal or external command,
    operable program or batch file.
  • Verify the size of the logFile.log file after clearing the contents, it becomes 0 bytes.
    C:\windows\system32>dir F:\logFile.log
     Volume in drive F is New Volume
     Volume Serial Number is 3446-545B
    
     Directory of F:\
    
    12-08-2020  16:57                 0 logFile.log
                   1 File(s)              0 bytes
                   0 Dir(s)  71,822,176,256 bytes free
    

 

Note: I have done this activity on Microsoft Windows 10.

Last Updated: August 19, 2020

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Telegram (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
Prev Article
Next Article
Tags:Windows Windows 10

3 Comments

  1. Solaire

    type nul > file_here
    worked for me without erro

  2. JohnA

    LOL…Surprisingly this works.

  3. Sergei

    Thanks for the article, it is usefull. It also works if you type the same without cat:
    /dev/null > logFile.log

    And as Solaire said, it also works with:
    nul > logFile.log

    Despite it appears an Internet Security Configuration warning in my case, the file gets finally cleared.

    Regards!

Leave a Reply Cancel Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Popular
  • Recent

Categories

  • Android (2)
  • Blogger (16)
  • Domain and Hosting (1)
  • Hardware Issues (7)
  • HP-UX (55)
  • HPE Data Protector (9)
  • IBM Lotus Notes (2)
  • IBM WebSphere Application Server (16)
  • Internet Tips & Tricks (15)
  • iOS (8)
  • JBoss/WildFly Application Server (2)
  • Linux (76)
  • macOS (15)
  • Microsoft Windows (31)
  • News and Updates (11)
  • Oracle Database (5)
  • SSL/TLS (1)
  • Storage Servers (23)
  • Tools/Softwares (1)
  • VMware ESXi (17)
  • Web Servers (14)
  • WordPress (5)

Archives

DbAppWeb.com

Solution of Database, Application and Web Server Problems

About DbAppWeb.com

One Stop Solution for Database Server, Application Server and Web Server Problems.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

DbAppWeb on Social Media

Copyright © 2026 DbAppWeb.com
Terms and Conditions   Theme by MyThemeShop.com
 

Loading Comments...