Search code examples
windowscmd

What is the meaning of cd. > for creating empty file in windows CMD?


"What is the meaning of cd. > for creating empty file in windows CMD?" In my view point CD means change directory but why i have to put .> for creating empty file in windows CMD?

C:\Users\smith\Desktop\web>cd. >index.html

Solution

  • > redirects output from the preceding operation to a file handle. Unfortunately, there's no straighforward way to output an empty string with echo in cmd, so if you use:

    echo. > newfile.txt
    

    for example, you end up with newfile.txt containing a trailing new-line.

    cd. "changes" the location to, well, the current location (so effectively does nothing) and then it outputs... well, nothing! The effect being that:

    cd. > newfile.txt
    

    results in an empty text file