Linux/UNIX 'touch' Equivalent on Windows aka How to Create a File Without a Name on Windows

Windows Explorer doesn’t allow you to create files that start with . because it interprets that as not having a file name.

"You must type a file name."

On Linux/UNIX you would simply use: touch .gitignore.

"Linux touch output"

Windows doesn’t have a touch command.

But if you run an invalid command and pipe that to a file that starts with a dot, the file will be created.

For example,

If you run foo>.gitignore the .gitignore file will still be created - even though foo is not a valid command. Feel free to try with any command, such as bar>.gitignore.

Even though the command outputs an error, the file is still created.

"Viewing the file"

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. foo>.gitignore
  6. fsutil file createnew .gitignore 0
  7. nul > .gitignore
  8. notepad .gitignore
  9. In Windows Explorer, name the file .gitignore. (with a period at the end of the file name) 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.