Windows CMD Commands for Beginners (Create, Delete, Access Folders & Files)

Open the Windows command prompt and use the following command to create and navigate the folder. You can also place and run these commands inside a .bat file (for automation)

Windows CMD commands

To create a folder

mkdir folder_name (or Folder_name with location)

Example : mkdir D:\python books

To Navigate to that folder

cd D:\python books

If CMD won’t change the directory to another drive

Use /d after the cd.

cd /d D:\files

You can also use the drive letter with a semicolon to change the drive

C:\> d:

To rename the folder

ren D:\python books python learning material

SEE ALSO: Best Windows Shortcut Keys for Programmers

To list the files in the current directory

dir

Note: use dir /? To get the build in help documentation to know more about dir command to sort field with size, name etc.

Move files from one location to another location

move hello.txt D:\

To move multiple files with same file extention

Use wildcard to specify the file patter, if you want to move multiple files.

move *.txt C:\Users\public\Desktop

Note: It will not overwrite files, if its already in the destination folder.

If you want to overwrite existing file, then use the following command. Also, use (move /?) to get additional information & options.

move /Y *.txt C:\Users\public\Desktop

To copy Files

copy (source) (destination)

Ex: copy hello.txt D:\

To copy all files inside the folder

xcopy (source) (destination) /E /I /H

Ex: xcopy D:\rani C:\Users\Public\Desktop /E /I /H

Note:-

  • /E – Copies directories and subdirectories inside the folder
  • /I  – create the directory structure at the destination
  • /H – Copies the hidden and system files also.

To create text files

Use echo command to create text files.

echo (text) > (file name with extension)

Example : echo Hello world >mytext.txt

The will create a file name mytext.txt with the content “hello world” in the current directory.

To read a text file content

Use type command to open and read a text file

type (filename with extension)

type mytext.txt

To change the content inside text file

Use the echo command followed by ‘>” (redirection operator to overwrite text fiel content.

echo  Good Morning>mytext.txt

You can also use copy con command followed by the file name to edit the text file content.

copy con mytext.txt

Edit the content you need. Then press the Ctrl + Z and press Enter key to save the changes.

To delete a file

del mytext.txt

To delete a folder or directory (use the command be carefully. Because it will delete the folder without your confirmation)

rmdir /s /q folder_name

Or use the command with rd instead of rmdir

rd /s /q folder_name

Note: use rmdir or rd with the /s option to delete the folder.

How to start the specific application

Use start command followed by the name or path of the fiel.

start chrome

or

start C:\Program Files\Google\Chrome\Application\chrome.exe

To clear previously typed commands & output on the command panel

cls

To Close the command prompt

Type exit and press Enter.