Touch command not working in Terminal of VSC
Solution 1
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 2
If you want to use the touch command, use bash as your terminal. It will work then
Solution 3
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 4
cat > filename
works for me in windows
mossexploding
Updated on June 17, 2022Comments
-
mossexploding almost 2 years
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
-
jeppoo1 about 4 yearsThis throws me the following error in VSCode: The term 'code' is not recognized as the name of a cmdlet, function, script file, or operable program.
-
Leonard almost 4 years@jeppoo1 That's because you don't have VSCode added to your PATH. PATH is where your computer will look for first when you input commands like "code". You need to let the computer know that typing "code" in terminal means open VSCode.
-
Jack H over 2 yearsthis worked for me in VSC