Create an empty file on the commandline in windows (like the linux touch command)

Cover Image for Create an empty file on the commandline in windows (like the linux touch command)
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

How to Create an Empty File on Command Line in Windows

So you're on a Windows machine, trying to create an empty file using the command line, and you encountered the frustrating error message: "'touch' is not recognized as an internal or external command, operable program or batch file." Don't worry, we've got you covered! In this guide, we'll explore common issues, provide easy solutions, and help you find a Windows equivalent to the 'touch' command.

The Problem: 'touch' Command is Not Recognized in Windows

The 'touch' command is commonly used in Linux, macOS, and Unix systems to create or modify a file's timestamp. Unfortunately, Windows does not have a built-in 'touch' command, which is why you encountered the error message.

Solution 1: Using the echo Command

One simple way to create an empty file on the Windows command line is by using the echo command. Here's how it works:

  1. Open the Command Prompt by pressing Win + R, typing cmd, and hitting Enter.

  2. Navigate to the directory where you want to create the empty file. You can use the cd command to navigate through directories. For example, cd Documents to enter the "Documents" directory.

  3. Type the following command to create an empty file:

    echo. > filename.ext

    Replace filename with the desired name of your file and ext with the appropriate file extension (e.g., txt, html, css).

  4. Hit Enter, and voila! You've just created an empty file.

Solution 2: Using the fsutil Command

If you prefer a more direct alternative, you can also use the fsutil command, which is available in Windows. Here's how:

  1. Open the Command Prompt as mentioned in Solution 1.

  2. Navigate to the directory where you want to create the empty file.

  3. Type the following command:

    fsutil file createnew filename.ext 0

    Replace filename with the desired name of your file and ext with the appropriate file extension.

  4. Press Enter, and there you have it – an empty file created using the fsutil command.

Solution 3: Using Third-Party Software

If you frequently work with the command line and need more advanced file creation options, you may consider using third-party software like Git Bash or Cygwin. These programs provide a more Unix-like environment on Windows, including the 'touch' command.

You can download Git Bash from here and Cygwin from here.

Alternatively, you can also explore Windows Subsystem for Linux (WSL), which allows running a Linux distribution directly on your Windows machine. With WSL, the 'touch' command and other Linux utilities are readily available.

Conclusion

Creating an empty file on the Windows command line doesn't have to be a struggle. By using the echo command, fsutil command, or third-party software like Git Bash or Cygwin, you can easily replicate the functionality of the 'touch' command in Linux.

So go ahead, try out these solutions, and save time by automating file creation on your Windows machine. If you found this guide helpful, don't forget to share it with your fellow techies! 💻📂

Got any other Windows command line questions or suggestions? Drop us a comment below, and let's keep the conversation going! 👇🤝


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello