Trusted answers to developer questions

What is the PowerShell equivalent of 'touch'?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

svg viewer

In Linux, the touch command is used to generate a new file. However, in PowerShell, this command does not work; so, alternatives are used.

The easiest way is to use:

$null > filename

This generates a file in Unicode, so, the file will not be empty. To generate a file in ASCII use:

$null | sc filename

Another way to create files and folders is to use New-Item:

ni filename

This creates a file or folder,​ depending on the extension given.

Sometimes it is also used to change the timestamps (i.e., dates and times of the most recent access and modification) on existing files and directories.

RELATED TAGS

powershell
touch
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?