Windows Command Line Tutorial
0. A few Tips
-
Use /? to get more information
if you want to know more about one command line order,you can type the optional “?” after the order you want to know. Then you will get the hint or the assistance.
rmdir /?
-
Use Tab to get hint
Press Tab key can help get the hint.
- if you type “cd J”, the command match the first file with the letter ‘J’.
- If it is not want you want ( you have many files with J letter), you can press Tab again to get the next file with ‘J’ letter.
-
Clear the Screen
cls
1. Directory
1.1 Create and Remove Directories
-
make directories
mkdir test //test is the name of the directory
-
remove empty directory
rmdir test
- What’s notable is that the directory “test” must be empty if you want to delete it with only “rmdir” order.
-
remove non-empty directory
rmdir /s test
2. Drive
if you want to know all the available drive on your computer, you can use the following order
wmic logicaldisk get name
2.1 Change Drive
if your current position is C disk and you want to move to D disk, you can type " D: " to change your drive.
C:\User\Frank>D:
- C disk, D disk is actually a USB Drive.
- There are also DVD drive and CD drive etc
3. File Attribute
-
see the attribute of the file
attrib
- A file can have multiple attribute at the same time. For example the file can be Read-only and Hidden.
4. Files
4.1 Delete Files
delete bacon.txt
4.2 Overwrite a file
echo helloworld > bacon.txt
-
By this order you can create the file called bacon.txt and write “helloworld” into it.
-
But if the file already exists before you echo, then your content will overwrite the original content!
4.3 Append to a file
if you just want to append some words then use >> to append
echo tunafish >> bacon.txt
4.4 Copy A file
- copy
copy srcfile destFolder //this is the fomat
copy test.txt TestFolder
copy test.txt d:
-
xcopy
- if you do not add /s then only files will be copy to the destFolder
- if you add /s then the subFolder will also be copy to the destFolder except empty ones
xcopy srcFolder destFolder /s
4.5 Moving Files
move srcFolder destFolder
4.6 Rename Directory
rename originFolderName newFolderName