Windows Equivalent of Linux or Unix “Touch” Command

In Linux and Unix there is a “touch” command which will update the timestamp of a file without modifying the contents.  You can also create an empty file without having to open an application among other actions.  In Windows there isn’t a direct equivalent, but you can get close by using the “copy” command with a “+” at the end of the filename while specifying no destination file.  The + symbol points the copy operation back to the source file.  This will update the timestamp while not modifying the contents of the file.

Ex.

copy SampleFile.txt+

WindowsEquivTouch1

WindowsEquivTouch2

This process was helpful for my customer testing out automated CI/CD processes with Azure DevOps and Git.  Hopefully this will be useful to someone else.  Enjoy.

 

-Frog Out

8 thoughts on “Windows Equivalent of Linux or Unix “Touch” Command

  1. In Windows 10, the timestamp is NOT updated. Plus, you have to add a “/Y” to the command to keep from being asked if you want to overwrite the file.

    Like

    • What host / shell are you running the command?

      I am currently getting same error when running the above in PowerShell, but does work in CMD (command line). May be an update to PowerShell that changed as this previously did work at original publication.

      Like

Leave a comment