PowerShell equivalent of the touch command in Linux

May 02, 2022 · 1 min read · Post a comment

There might be a point in your IT career where you need to switch to a Windows OS dev machine whatever you like it not because the CTO decided to put all eggs in the Microsoft Azure basket. Now, the transition from Bash to PowerShell is always a pain the arse, so let’s start with a simple command, the touch command.

For those of you who are unfamiliar with this command, it allows us to create or modify file timestamps, although most of the cases is used for a simple file creation. Besides the PS equivalent that you’ll see it below, there are three other methods I want to share with you on how to create empty files in PowerShell.


  • Windows


The PowerShell equivalent

Open PowerShell and run the following command:

$null | sc file.txt

The native PowerShell command

Open PowerShell and run the following command to create an empty file in the current working directory:

New-Item -Path . -Name "file.txt" -ItemType "file"

or, a shorter version:

ni file.txt


If you haven’t heard about the Windows Subsystem for Linux (WSL) I suggest to search for their official docs, but basically it lets you run a Linux environment without the virtual machine tools hassle.

Step 1. Install Windows Subsystem for Linux.

Step 2. Press the Windows Key on your keyboard and start typing wsl. Once it pops out, click and run the touch command as you do in a Linux env.

touch file.txt

Note(s): You can do the same if you got Git for Windows installed. Just search for git bash instead and the rest is identical as the steps above.


As always, if you can think of any alternative solution, feel free to write a comment below. On a side note, follow our official channel on Telegram.