Open In App

How to Create a File in VSCode using Terminal?

In a few cases touch or new-item or any other base keywords may not be used to create a file in vs code due to the absence of extensions, but using the following approach you can create and code any type of file with ease. In this article, you will learn about how to create a file with any file type extension in vs code using a terminal with commands. 

Creating a File in VSCode using Terminal

There are primarily two methods to create a file in VSCode using the terminal, you can use the “Code” keyword to create a file, or you can use the “echo” keyword to create a new file. 



Use the “Code” keyword

Step 1: Open the Visual Studio Code. 

 

Step 2: Click on the Terminal and New Terminal, to open a terminal. or press ctrl + ` to open the terminal.



 

Step 3: A new terminal is opened. Go to the desired folder. Now use the following command to create a new file with any file extension type and also to write something or code in a file at your desired location path. Now, type “code filename.extension”, to create the desired file, where filename is the name of the file you want to make, and .extension is the extension you want to provide to the file. For example, to create a .txt file, write “code samplefile.txt”, and to create a .py file, write “code sumTwoNum.py”. Now, you can do “ls” to view all the files in the current directory. 

 

 

Step 4: The file has been created. Write some text in the file as a sample and save your file. Use Ctrl + S to save the file.

 

Use “echo” keyword

Step 1: Open Visual Studio Code. Go to the desired location, where you want to create a file. Now use the following command to create a new file with any file extension type and also to write something or code in a file at your desired location path. Now, type “echo > “filename.extension””, to create the desired file, where filename is the name of the file you want to make, and .extension is the extension you want to provide to the file. For example, to create a .txt file, write “echo > “gfg.txt””, and to create a .py file, write “echo > “gfg.py””.

 

Step 2: The file has been created. Write some text in the file as a sample and save your file. Use Ctrl + S to save the file.

 

Article Tags :