'Touch command not working in Terminal of VSC

I'm new and still trying to figure out how to configure my development environment. I'm getting an error when using the touch command in Visual Studio Code. I can use mkdir to create a directory, but can't create a .php file. Here's the error I'm getting. Any ideas? Thank you!

touch : The term 'touch' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + touch new.php + ~~~~~ + CategoryInfo : ObjectNotFound: (touch:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException



Solution 1:[1]

To create a new empty file in PowerShell, you can use:

ni new.php

or, without aliases and defaults:

New-Item -Path X:\path -Name new.php -ItemType File  

For details see Get-Help New-Item or view online

Solution 2:[2]

As Lex Li said

You are not in a Linux/macOS terminal, but a terminal panel in VSCode, which runs PowerShell in fact. So touch is obviously not a command there.

Here's the command you can use for VSC to create a new file

code -r newFile.js

To open an existing file use the command

code -r fileName.js

Solution 3:[3]

If you want to use the touch command, use bash as your terminal. It will work then

Solution 4:[4]

Since you are on a Windows system using the PowerShell as the default terminal for VSCode, know that there is no such command (cmdlet) called touch.

However, there is a workaround to create new files from PowerShell using the following command:

echo $null >> filename

Note: As this is a workaround, I suggest you use it with caution.

Solution 5:[5]

cat > filename

works for me in windows

Solution 6:[6]

if you use git then, go to the folder of your project where you want to create a file, then right click and chose "git bash here". a terminal/command prompt type window will appear now you can type command "touch .newfilename".

Solution 7:[7]

For Creating file from command prompt like in linux New-Item tsconfig.json

New-Item tsconfig.json

New-item is powershell command. Here creating tsconfig.json file simply use new-item command

Creating Alias

touch is linux command you can create alias for touch like this.

![enter image description here

set-alias touch new-item

Solution 8:[8]

Depending on the OS you are running on it might need a different configuration, for Linux (mint) I had to use the ni command to accomplish this

Try something like ni fileName.anything

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 AnnaG
Solution 4 Dhruv Joshi
Solution 5 Shubh
Solution 6 Mujtaba Tarar
Solution 7
Solution 8