Touch command not working in Terminal of VSC

15,359

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

Share:
15,359
mossexploding
Author by

mossexploding

Updated on June 17, 2022

Comments

  • mossexploding
    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
    jeppoo1 about 4 years
    This 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
    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
    Jack H over 2 years
    this worked for me in VSC