Linux Touch Equivalent for Windows AKA How to Create a File Without a Name in Windows

Windows Explorer doesn’t allow you to create a file without a name:

Windows doesn’t have a native “touch” equivalent, which is a native Linux program that allows you to create empty files and change timestamps.

But…

If you run “touch>.gitignore” (or any of the other options below) from the command line, the file is created. Also, if you run it again, the file’s timestamp will be updated. It won’t change attributes like touch on Linux does.

Here are some other ways that work as well.

  1. copy nul .gitignore
  2. copy con .gitignore, hit enter, then hit ctrl+z
  3. cat>.gitignore, hit enter, then hit ctrl+c
  4. echo > .gitignore
  5. touch>.gitignore
  6. fsutil file createnew .gitignore 0
  7. nul > .gitignore
  8. notepad .gitignore
  9. In Windows Explorer, name the file “.gitignore.” and Windows will rename it to “.gitignore”
  10. bash -c “touch .gitignore”

Let me know if you know of any other ways and I’ll add them to the list.

Jon