Creating new file with touch command in PowerShell error message
If you need a command touch
in PowerShell you could define a function that does The Right Thing™:
function touch {
Param(
[Parameter(Mandatory=$true)]
[string]$Path
)
if (Test-Path -LiteralPath $Path) {
(Get-Item -Path $Path).LastWriteTime = Get-Date
} else {
New-Item -Type File -Path $Path
}
}
Put the function in your profile so that it's available whenever you launch PowerShell.
Defining touch
as an alias (New-Alias -Name touch -Value New-Item
) won't work here, because New-Item
has a mandatory parameter -Type
and you can't include parameters in PowerShell alias definitions.
If you're using Windows Powershell, the equivalent command to Mac/Unix's touch is: New-Item textfile.txt -type file
.
For single file creation in power shell :
ni textfile.txt
For multiple files creation at a same time:
touch a.txt,b.html,x.js
is the linux commandni a.txt,b.html,x.js
is the windows power shell command