Some Useful CMD Commands.
CMD refers to the Command Prompt in Windows, a command-line interface program that allows users to execute commands, run scripts, and manage tasks within the Windows operating system. Officially known as "cmd.exe," this legacy command-line interpreter has been part of Microsoft Windows since Windows NT. It provides a text-based interface for executing system functions, batch files, and simple scripts.
Features of Command Prompt include:
Batch scripting: Users can write batch (.bat) files, which are simple scripts composed of command line instructions executed sequentially.
System management: It allows for managing Windows environments via various commands for handling files, directories, services, and other system components.
Compatibility: Command Prompt supports a wide range of commands that have been part of Windows operating systems for decades.
Here are some cmd commands which are frequently used with using method.
1) CHDIR OR CD - Change Directory
2) DATE - Display Date
3) TIME - Display Time
4) MKDIR OR MD - Make Directory
5) DIR - Display Directory
6) RMDIR OR RD - Remove Directory
7) RENAME OR REN - Rename
8) ERASE OR DEL - Delete File or Folder
9) TYPE - Show Contents of File
10) COPY - Copy File and Folder
11) MOVE - Move File and Folder
1) CHDIR OR CD : This command is used to change the current working directory.
Uses :
To change to another directory: Simply type CD followed by the path to the directory. For example, CD Documents changes the current directory to the Documents directory (relative to the current location).
Syntax CD [Drive :] [Path]
e.g. : CD C:\user\Kisna
To move up one directory level: Type CD.. to go up one directory level. This command moves the working directory up to the parent directory.
Syntax: CD..
To go to the root directory: Typing CD \ will change the directory to the root directory of the current drive.
Syntax: CD \
To change the drive and directory: If you want to change to a directory on another drive, you also need to include the drive letter. For example, CD D:\Games switches the current directory to the Games folder on the D: drive.
Syntax: CD [DRIVE:][PATH]
e.g. : CD D:\user\Kisna
2) DATE : The DATE command in the Command Prompt (cmd) on Windows operating systems is used to display or set the system's date.
Uses :
To display date: Type DATE and hit enter . It will show the current date.
Syntax: DATE
To change current date: Type DATE followed by new date.
Syntax :DATE [MM-DD-YYYY]
e.g. : DATE 07-26-2024
3) TIME : This cmd command is used to display current time or change the time.
Uses :
To display time : Type TIME and press enter. It will show the current time.
Syntax: TIME
To change current date: Type TIME followed by new date.
Syntax :DATE [HH:MM:SS AM/PM] ( For 12-hour clock)
DATE [HH:MM:SS] ( For 24-hour clock)
e.g. DATE 22:54:02 or 11:55:08 AM
4) MKDIR OR MD: It is used to make or create a new directory.
Uses:
To make directory : Type MD followed by name of directory . It creates a new folder within the working directory.
Syntax: MD [name_of _folder]
e.g. MD Kisna
5) DIR : It is used to display a list of directories, files and subdirectories within a directory.
Uses:
Basic Usage: Simply type dir and press Enter to see the contents of the current directory.
Syntax: DIR
Specify a Directory: You can specify a directory to see its contents, e.g., dir C:\Users will list the contents of the Users directory on the C: drive.
Syntax: DIR [DRIVE:][PATH]
e.g. : DIR D:\user\kisna
Using Wildcards: You can use wildcards to filter the results, e.g., dir *.txt lists all text files in the current directory.
Additional Options: The dir command has various switches for different outputs, such as /S for listing files in specified directory and all subdirectories, /P to pause after each screen of information, and /A to display files with specified attributes.
6) RMDIR OR RD: It is used to remove or delete a directory.
Uses.
To remove empty directory: Type RD followed by name of directory and press enter. It will delete that empty folder within the working directory.
Syntax : RD [NAME_OF_DIRECTORY]
e.g. : RD My Files
To delete non-empty directory: Type RD /s followed by name of folder. It Will remove the non-empty folder.
Syntax: RD /s [NAME_OF_DIRECTORY]
To delete non-empty directory without confirmation: Type RD /S /Q followed by name of non-empty directory and hit enter . It will delete the folder which contains files or folder without prompting to confirm the deletion.
Syntax: RD /S /Q [NAME_OF_DIRECTORY]
e.g. RD /S /Q My Files
7) RENAME OR REN: It is used to rename a folder or a file.
Uses:
To rename a file: Type REN followed by the current file name and then the new file name and press enter.
Syntax: REN [OLD_FILE_NAME] [NEW_FILE_NAME]
e.g. : REN Kisna.txt Balram.txt
To rename a folder: Type REN followed by current folder name and then new folder name and hit enter.
Syntax: REN [OLD_FOLDER_NAME] [NEW_FOLDER_NAME]
e.g. : REN Kisna Balram
8) ERASE OR DEL: It is used to delete a file.
Syntax: DEL [FILE_NAME]
DEL Kisna.htm
9) TYPE : It is used to display the contents of a text file.
Uses :
To see contents: Type TYPE followed by name of file and press enter.
Syntax: TYPE [NAME_OF_FILE]
e.g. : TYPE Kisna.htm
To combine files: Type TYPE followed by name of first file and then second file and press enter.
Syntax: TYPE [FILE_NAME_1] [FILE_NAME_2]
TYPE Kisna.htm Balram.htm
10) COPY: It is used to copy a file from one location to another location .
Uses:
To copy a single file: Type COPY followed by path of the file and the another path in which file is to be copied and hit enter.
Syntax: COPY [FILE_PATH_1] [PATH_2]
e.g. : COPY C:\Users\Example\file1.txt D:\Backup\file1.txt
To copy multiple files in a directory: Type COPY and then use wildcard(*) in the file path and type another path and press enter.
Syntax: COPY [FILE_PATH_1\*.EXT] [PATH_2]
copy C:\Users\Example\*.txt D:\Backup\*.txt
To make a text based file : Type COPY CON followed by name of file and hit enter. Then write something you want to store in the file . After finished press F6 or Ctrl+Z and then enter.
Syntax: COPY CON [FILE_NAME] <ENTER> [WRITE SOMETHING] <F6> <ENTER>
e.g. : COPY CON kisna.txt <ENTER>My name is Kisna <F6> <ENTER>
11) MOVE: It is used to move a file or a folder from one location to another path. It can be used similarly to the COPY command.
12) ECHO: It primary use is to display messages or to turn on or off echoing of command in batch file. It is also used for creating text based files.
Uses:
To display a message: Type ECHO followed by the message you want to display.
Syntax: ECHO [YOUR_MESSAGE]
e.g. : ECHO Hello, World!
To Turn Echo On or Off: By default, when you run a batch file, each command in the file is displayed, or "echoed," on the screen as it is executed. You can control this behavior using ECHO ON or ECHO OFF.ECHO OFF disables the display of subsequent commands, which is useful for making the output of batch files cleaner.ECHO ON will enable the display of each command again.Example in a batch file:
@ECHO OFF
ECHO This is a batch file.
REM The following command will not be displayed
DIR
ECHO ON
ECHO Displaying the directory listing above.
To create text based files: Type Echo Followed by the contents you want to store and then greater than sign and then file name and hit enter.
Syntax: ECHO [CONTENT_HERE] > [FILE_NAME]
e.g. : ECHO This is my file > myfile.txt
(Note : Other text based files like .bat, .htm etc can also be made using ECHO.)
To add text to existing file: Type ECHO followed by the content you want yo add to the file and a pair of greater than sign and then name of the file and hit enter.
Syntax: ECHO [NEW_CONTENT_HERE] >> [FILE_NAME]
e.g. : ECHO Adding this content to the existing file >> myfile.txt
