1. Lesson objectives
This lesson will instruct students on how to use basic commands in Command Prompt on Windows 10.
2. Introduction to the Command Prompt
Nowadays, Graphic User Interface (GUI) programs are supported by most personal computer operating systems, making computer operations simpler. Additionally, it is possible to perform most computer tasks using Command Line Interface (CLI). In Windows OS, the command line interface is called Command Prompt.
3. Guide for Using Command Prompt
To use CMD, press the Windows + R key combination. This will open the Run dialog box. Enter cmd
in the box and then click OK.
The Command Prompt window will appear.
Here are some basic commands you can use in CMD:
# | Command | Function |
1 | DRIVE: (For example, E:) | Change the current drive |
2 | DIR [drive:][path][filename] /P /W /S /A | Displays a list of files and subdirectories in a directory. /P: Pauses after each screenful of information. /W: Uses wide list format. /S: Displays files in specified directories and all subdirectories. /A: Displays files with specified attributes. (/AH: Hidden files; /AR: Read-only files; /AS: System files; /AA: Files ready for archiving) |
3 | CD [/D] [drive:][path] CD [..] | Displays the name of or changes the current directory. CD.. specifies that you want to change to the parent directory.CD\ switch back to the root directory |
4 | MKDIR [drive:]path MD [drive:]path | Creates a directory. |
5 | RENAME [drive:][path]filename1 filename2. REN [drive:][path]filename1 filename2. | Renames a file or files. |
6 | TREE [drive:][path] [/F] [/A] | Graphically displays the folder structure of a drive or path. /F: Display the names of the files in each folder. /A: Use ASCII instead of extended characters. |
7 | RD [/S] [/Q] [drive:]path | Removes (deletes) a directory. /S: Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree. /Q: Quiet mode, do not ask if ok to remove a directory tree with /S |
8 | COPY CON [path]\filename | Create a new file F6 or Ctrl + Z: save new file Ctrl + C: cancel file creation |
9 | TYPE [drive:][path]filename | Displays the contents of a text file or files. |
10 | REN [drive:][path]filename1 filename2 | Renames a file or files. |
11 | COPY [filename_01] + [filename_02] [new_filename] | Merge contents of files |
12 | COPY [source_path] [destination_path] | Copy files |
13 | MOVE [drive:][path]filename1[,…] destination | Moves files and renames files and directories. |
14 | DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names | Deletes one or more files. |
15 | ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U] [drive:][path][filename] [/S [/D]] [/L] | Displays or changes file attributes. +: Sets an attribute. -: Clears an attribute. A: Archive file attribute, read-only file attribute. H: Hidden file attribute S: System file attribute. |
16 | DATE [/T | date] | Displays or sets the date. |
17 | TIME [/T | time] | Displays or sets the system time. |
18 | CLS | Clear the screen. |
19 | FORMAT [DRIVE:] | Formats a disk for use with Windows. |
20 | LABEL [DRIVE:] [LABEL] | Creates, changes, or deletes the volume label of a disk. |
21 | VOL [DRIVE:] | Displays the disk volume label and serial number, if they exist. |
22 | SHUTDOWN -s -t [a] (a is second) | Turn off the computer |
4. How to use PowerShell on Windows
PowerShell is a command line interface program that’s gradually replacing Command Prompt on Windows. It works on the .NET environment, and the .NET Framework includes commands and programming languages.
PowerShell has a parallel development with its Integrated Scripting Environment (ISE) which includes a graphical user interface and various tools for manipulating PowerShell. Windows has been developing PowerShell for a considerable amount of time and its updated version with many improved features has been introduced since Windows 8.1 and Windows Server 2012.
To open the Windows PowerShell interface on Windows, press the Windows + R key combination, and type “powershell” in the command prompt.
The program interface for Windows PowerShell.
For commands on PowerShell, students can refer here.
5. Requirement of practice
Let’s create a directory tree in the image below:
Note: Do not use the “\” in Command Prompt, and when you enter Command Prompt, you will see:
a. Use the command to create 2 files GiaoTrinh.txt and BaiTap.txt with the following content in the directory C:\QLHVIEN\TINHOC. The contents of the GiaoTrinh.txt file are as follows: “Textbook of TH-PCMT for IT students“. The content of the BaiTap.txt file is as follows: “Manipulating command line commands on Windows“.
b. Merge GiaoTrinh.txt and BaiTap.txt to NoiDung.txt.
c. Move all newly created files to C:\QLHVIEN\TINHOC\CANBAN.
d. Rename the file NoiDung.txt to Content.doc.
e. Create folder VP1, VP2 in folder VANPHONG.
f. Delete the VP1 folder.
g. Delete the VANPHONG folder.