How to Create a File in VSCode using Terminal? (original) (raw)
Last Updated : 26 Jun, 2025
Sometimes, commands like touch or **New-Item**may not work as expected in VS Code due to environment limitations or missing shell extensions. However, using simple terminal commands, you can easily create and edit files of any type right from VS Code. , Let's learn how to create new files using the code and echo commands in the terminal.
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.






