Windows equivalent of 'touch' (i.e. the node.js way to create an index.html)

后端 未结 19 2282
一整个雨季
一整个雨季 2020-11-28 00:47

On a windows machine I get this error

\'touch\' is not recognized as an internal or external command, operable program or batch file.

19条回答
  •  借酒劲吻你
    2020-11-28 01:35

    As Raghuveer points out in his/her answer, ni is the PowerShell alias for New-Item, so you can create files from a PowerShell prompt using ni instead of touch.

    If you prefer to type touch instead of ni, you can set a touch alias to the PowerShell New-Item cmdlet.

    Creating a touch command in Windows PowerShell:

    From a PowerShell prompt, define the new alias.

    Set-Alias -Name touch -Value New-Item
    

    Now the touch command works almost the same as you are expecting. The only difference is that you'll need to separate your list of files with commas.

    touch index.html, app.js, style.css
    

    Note that this only sets the alias for PowerShell. If PowerShell isn't your thing, you can set up WSL or use bash for Windows.

    Unfortunately the alias will be forgotten as soon as you end your PowerShell session. To make the alias permanent, you have to add it to your PowerShell user profile.

    From a PowerShell prompt:

    notepad $profile
    

    Add your alias definition to your profile and save.

提交回复
热议问题