mossexploding
mossexploding

Reputation: 131

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

Upvotes: 12

Views: 42253

Answers (12)

maxspan
maxspan

Reputation: 14147

This can be achieved by following the below steps.

  1. Install touch by using the below command. Reference
  2. npm install -g touch-for-windows
  3. Now go to your VS CODE terminal and type touch test.txt.
  4. to view the file type Start . in your terminal and you will see the new file text.txt in your folder. enter image description here

Upvotes: 0

Haroon
Haroon

Reputation: 41

you're trying to use the touch command in Visual Studio it will not be recognized as a valid command in Windows PowerShell. The touch command is a Unix, Linux command used to create an empty file, and it may not be available in your current environment. Alternatively, you can also use the following command in Windows PowerShell to create a new .php file:

New-Item -ItemType File new.php

This command creates a new file named "new.php" in the current directory.

enter image description here

Upvotes: 1

Abdul Malik
Abdul Malik

Reputation: 81

you should switch to the bash terminal and use touch command to create multiple files

Upvotes: 0

Saad Abbasi
Saad Abbasi

Reputation: 853

If you are using git then you can use directly git commands inside VS Code

Go inside VS terminal you can open a terminal by clicking terminal on top of the vs code Terminal tab.

Click on the down arrow and select Git Bash

That's it ;

enter image description here

Upvotes: 4

hamza sabri
hamza sabri

Reputation: 39

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

Upvotes: 1

Mujtaba Tarar
Mujtaba Tarar

Reputation: 11

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".

Upvotes: 1

lava
lava

Reputation: 7373

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

Upvotes: 1

Shubh
Shubh

Reputation: 595

cat > filename

works for me in windows

Upvotes: 1

AnnaG
AnnaG

Reputation: 41

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

Upvotes: 4

Himansh
Himansh

Reputation: 977

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

Upvotes: 12

user6811411
user6811411

Reputation:

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

Upvotes: 16

thepoetdj
thepoetdj

Reputation: 773

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.

Upvotes: 1

Related Questions