On a windows machine I get this error
\'touch\' is not recognized as an internal or external command, operable program or batch file.
The answer is wrong, it only works when the file does not exist. If the file exists, using the first does nothing, the second adds a line at the end of the file.
The correct answer is:
copy /b filename.ext +,,
I found it here: https://superuser.com/questions/10426/windows-equivalent-of-the-linux-command-touch/764721#764721
Use the following command on the your command line:
fsutil file createnew filename requiredSize
The parameters info as followed:
fsutil - File system utility ( the executable you are running )
file - triggers a file action
createnew - the action to perform (create a new file)
filename - would be literally the name of the file
requiredSize - would allocate a file size in bytes in the created file
From the Terminal of Visual Code Studio on Windows 10, this is what worked for me to create a new file:
type > hello.js
echo > orange.js
ni > peach.js
If you have Cygwin installed in your PC, you can simply use the supplied executable for touch (also via windows command prompt):
C:\cygwin64\bin\touch.exe <file_path>
As Raghuveer points out in his/her answer, ni
is the PowerShell alias for New-Item
, so you can create files from a PowerShell prompt using ni
instead of touch.
If you prefer to type touch
instead of ni
, you can set a touch
alias to the PowerShell New-Item
cmdlet.
Creating a touch command in Windows PowerShell:
From a PowerShell prompt, define the new alias.
Set-Alias -Name touch -Value New-Item
Now the touch command works almost the same as you are expecting. The only difference is that you'll need to separate your list of files with commas.
touch index.html, app.js, style.css
Note that this only sets the alias for PowerShell. If PowerShell isn't your thing, you can set up WSL or use bash for Windows.
Unfortunately the alias will be forgotten as soon as you end your PowerShell session. To make the alias permanent, you have to add it to your PowerShell user profile.
From a PowerShell prompt:
notepad $profile
Add your alias definition to your profile and save.
as mentioned
echo >> index.html
it can be any file, with any extension then do
notepad index.html
this will open your file in the notepad editor