A .bat file is a plain-text file that tells Windows to run a series of commands in order, one after another

The ".bat" stands for "batch," because the file batches multiple commands together instead of you typing them one at a time. When you double-click a .bat file, Windows opens the Command Prompt (the black window where you type text commands) and reads through the file line by line, executing each instruction. It is a way to automate repetitive tasks without writing a full program.

You have probably seen .bat files if you have ever downloaded software, set up a development tool, or worked in an office where IT staff distribute setup scripts. They are common because they are simple to write and they work on any Windows machine without needing special software installed.

Key Takeaways

  • A .bat file contains a list of Windows Command Prompt commands that run automatically when you open the file.
  • You can open and edit a .bat file in Notepad or any plain-text editor to see exactly what commands it will run.
  • Running a .bat file from an unknown source carries a real risk because it can delete files, change settings, or install unwanted software without asking permission first.
  • Windows may show a security warning before running a .bat file downloaded from the internet, and you should read that warning carefully before proceeding.

How a .bat file actually works

When you double-click a .bat file, Windows launches Command Prompt and feeds it the contents of the file as if you had typed each line yourself. Each line is a separate command. For example, a simple .bat file might contain:

cd C:\Users\YourName\Documents dir pause

The first line changes the folder to your Documents folder. The second line lists all the files in that folder. The third line pauses so you can read the output before the window closes. If you typed those three commands manually in Command Prompt, you would see the same result.

The power of .bat files comes from chaining commands together. A real-world example: a company IT department might create a .bat file that copies files from one network location to another, deletes temporary files, and then restarts the computer — all without anyone having to type anything or remember the order of steps.

Where you are likely to encounter .bat files

Software installers sometimes use .bat files to set up programs or configure your system. Game launchers occasionally use them to check for updates or adjust settings before the game starts. Developers use them to automate testing or to build software. System administrators use them to manage computers across a network.

You might also see .bat files in compressed folders (like .zip files) that you download from the internet. For instance, if you download a tool to optimize your computer or a utility to manage files, the download might include a .bat file that you run to complete the setup.

The security risk of running an unknown .bat file

Because a .bat file simply runs whatever commands are inside it, a malicious .bat file can do real damage. It could delete your files, change your Windows settings, install unwanted software, steal passwords, or disable your antivirus. Unlike a program with a user interface where you can see buttons and options, a .bat file runs silently in the background — you might not realize what it is doing until it is finished.

Windows tries to protect you by showing a security warning when you run a .bat file that came from the internet. The warning says something like "Windows protected your PC" or "Do you want to allow this app to make changes to your device?" This is your signal to stop and think: Do I trust the source of this file? Did I actually download it intentionally? If the answer is no, do not click through the warning.

The safest approach is to never run a .bat file unless you know exactly where it came from and why you need it. If you are unsure, you can open it in Notepad first to read the commands inside and see what it is supposed to do.

How to open and read a .bat file safely

To see what a .bat file contains without running it, right-click the file and choose "Open with" and then select Notepad (or any text editor). The file will open as plain text, and you can read all the commands. This is a safe way to inspect a .bat file before you decide whether to run it.

When you read a .bat file, look for commands that seem suspicious or that you do not recognize. Common command names include copy, del (delete), move, mkdir (make folder), and cd (change directory). If you see commands like powershell or curl followed by a web address, that is a sign the file is downloading something from the internet, which is a red flag. If you see reg add, the file is modifying your Windows registry, which is also risky if you do not know what it is doing.

The difference between .bat and other file types

A .cmd file is nearly identical to a .bat file — it is also a batch of commands for Windows Command Prompt. The difference is historical and technical; for practical purposes, they work the same way and carry the same security risk.

A .exe file is a compiled program — the code has been translated into machine language that Windows runs directly. You cannot open an .exe in Notepad to see what it does; it is binary data. A .bat file is human-readable text, which is why you can inspect it before running it.

A .ps1 file is a PowerShell script, which is a more advanced scripting language than batch commands. It can do more complex things, but it also carries similar security risks. Windows treats .ps1 files with extra caution and may refuse to run them unless you change your security settings.

When you might want to create your own .bat file

If you find yourself running the same sequence of commands repeatedly, you can save time by writing a .bat file. For example, if you regularly back up a folder to an external drive, you could create a .bat file that does the copy command automatically. You would just double-click the file instead of typing the command each time.

To create a .bat file, open Notepad, type your commands (one per line), and then save the file with a .bat extension instead of .txt. For instance, name it backup.bat instead of backup.txt. Make sure Notepad is set to save as "All Files" rather than "Text Documents" so it does not add .txt to the end automatically.

If you are new to Command Prompt commands, there are many online guides that show the syntax for common tasks. Start with simple commands and test them in Command Prompt first before putting them in a .bat file.

Frequently Asked Questions

Can a .bat file give my computer a virus?

A .bat file itself cannot carry a virus the way an .exe file can, but a malicious .bat file can download and run a virus, delete your files, or change your settings in harmful ways. The risk is in what the commands inside the file tell Windows to do, not in the file format itself.

Why does Windows show a warning when I try to run a .bat file?

Windows shows a warning because .bat files can make changes to your system without asking permission for each change. The warning is your chance to confirm that you actually want to run the file. If you did not download it yourself or do not recognize it, click "No" or close the warning.

Is it safe to run a .bat file from a company or software developer?

If the .bat file came directly from a company whose software you use or from a developer you trust, it is usually safe — but you can still open it in Notepad first to see what it does. Legitimate companies generally use .bat files for setup, updates, or maintenance tasks. If something in the file looks wrong or unfamiliar, contact the company before running it.

What happens if I delete a .bat file?

Deleting a .bat file just removes the file from your computer. It does not undo any changes the file may have made in the past. If a .bat file previously deleted other files or changed settings, those changes stay in effect unless you undo them manually.

Can I run a .bat file on a Mac or Linux computer?

No. .bat files are Windows-specific because they use Windows Command Prompt syntax. Mac and Linux use different command languages (like Bash). If you need to automate tasks on a Mac or Linux machine, you would use a shell script (.sh file) instead.