We can create files from command line in two ways. The first way is to use fsutil
command and the other way is to use echo
command. If you want to write any specific data in the file then use echo command. If you are not bothered about the data in the file but just want to create a file of some specific size then you can use fsutil
command.
To create file using echo
echo some-text > filename.txt
Example:
C:\>echo This is a sample text file > sample.txt C:\>type sample.txt This is a sample text file C:\>
To create file using fsutil
fsutil file createnew filename number_of_bytes
Example:
C:\data>fsutil file createnew sample2.txt 2000 File C:\data\sample2.txt is created C:\data>dir 01/23/2016 09:34 PM 2,000 sample2.txt C:\data>
Limitations
Fsutil
can be used only by administrators. For non-admin users it throws up below error.
c:\>fsutil file /? The FSUTIL utility requires that you have administrative privileges. c:\>
Thank you for the quick and dirty method since windows seems to lack the “touch” command.
How can we use these commands to ‘touch’ a file. Could anyone provide the exact command that can work as linux ‘touch’ for any type of file?
Windows does not lack “touch”. It is echo. As the post describes? type: echo “” Blah.cpp
for Windows users, try
echo README.md
touch works on a UNIX system.
dude, this isnt working on our school’s computers, can you tell another method that works on windows 8 computers please?
lmao it works at school PC
Make sure that you are typing in the code the right way. It happened to me when I typed in “echo This is a sample text file sample.txt”.
Thanks!
thanks!!
If you want to create a file with NO text in it do this:
at the CLI type “Echo.”: Your output should look like this:
C:\Temp>echo.
C:\Temp>
To write to a file:
C:\Temp> Echo. >test.txt
This will create a file with single space in the file.
I tried:
copy nul > file.txt
copy con somefile.txt
copy con somefile.txt
and then press and press ^Z (Ctrl+z) and press
How can I create multiple files at a time
@echo off > your-file-name.extension
this is awesome…thanks a lot