Arjun Chaudhary
Arjun Chaudhary

Reputation: 2453

Windows CMD TYPE command

I am learning from a tutorial and it used this command type NUL > introduction.js . I searched online TYPE is a command, i know > is redirection operation and last is the name of the file. And it creates an empty file. I dont't know the function of NUL but its equivalent to dev/nul of UNIX.

But can someone summarize the whole command in parts and what is the advantage of doing this instead of echo or other commands.

Upvotes: 4

Views: 30773

Answers (2)

Masoud
Masoud

Reputation: 425

In Windows command Prompt:

both type & echo can create a file

for creating empty file, for example a text file

TYPE nul > pathNewFile.txt

Echo > pathNewFile.txt

for adding content to new or existing file by Echo

Echo some text > pathNewOrExistingFile.txt

and for Type it puts content of another file

TYPE pathExistingFile.txt > pathNewOrExistingFile.txt

and in both of them for appending content instead of overriding content we use >> for >

Echo some text >> pathFileName.txt

Upvotes: 12

Masked Man
Masked Man

Reputation: 2538

In CMD help:

type /?
Displays the contents of a text file or files.

TYPE [drive:][path]filename

and NUL I think is an empty file symbol. so,

type NUL > introduction.js

reads the content of NUL "Which is an empty file", and write it to introduction.js conclusion:

You are creating an empty introduction.js file.

Upvotes: 4

Related Questions