Cmd

Basic Command Line in Windows

A quick and useful tool

Posted by Mike Lyou on January 4, 2020

查看中文版本(有配图)→

This article briefly introduced the common usage of command line.

During the building of my blog, I encountered the command line. Though solved the tasks at that time, I know nearly nothing about the command line. So today I am going to figure out what the basic command line can do for me.

Due to huge workload and little importance, not grapghs to illustrate.

Introduction to command line

What is the command line?

The command line, appears as cmd, is a handful tool that let you communicate directly with computer. It can perform some tasks much quicker than normal ways, and sometimes is the only way, like when you launch the jekyll serve. And it is cool.

It looks like DOS, but has little to do with DOS.

Access the command line

There are two ways to access the command line.

  • Method 1. Press Win + R to open Run → type cmd and Enter.

  • Method 2. Press Win to open Start menu → type cmd and click Command Prompt (here you can run as Admin).

And then you should see the window of cmd.exe.


Now we have launched the cmd.exe, what can we do next?

Below I will introduce several things we can do with command lines.

Common Commands about directories and files

Now we have launched the cmd.exe, what can we do next?

Below I will introduce several things we can do with command lines.

cd

By default, the cmd.exe is at directory of C:\WINDOWS\system32 or C:\Users\Username. You can see it once you open the cmd.exe.

If we want to search files or run programs in another directory, we have to change the directory to there.

Use cd NEW_PATH to change directory to NEW_PATH.

If NEW_PATH is at a drive other than C:, assuming it is E:, we need to change drive before that.

1
2
E:              # change drive
cd E:\NEW_PATH  # change directory

You can see the directory changes at the beginning of the new lines that pops up.

dir

List all the files and sub-directories in current directory.

mkdir

Use mkdir DIRNAME to create a new directory named DIRNAME

rmdir

Use rmdir DIRNAME to remove directory named DIRNAME.

Only empty directory can be removed. Trying to remove a nonempty directory will generate an error message.

del

Use del FILENAME.extension to delete file named FILENAME.extension.

help

If you don’t know what command is available, type help to see all commands.

Common commands about Windows systems

ping

Use ping command to check the responding time between an IP and your computer.

1
2
ping mikelyou.com
ping 185.199.110.153  # IP of mikelyou.com

You can check the IP of an website by this way as well.

ipconfig

Use ipconfig to reveal many network data of your computer.

systeminfo

Use systeminfo to see information about your Windows system.

shutdown

I don’t know where I can use these…

1
2
3
shutdown -s         # system will shutdown in 1 minute
shutdown -s -t 3600 # system will shutdown in 3600 seconds
shutdown -a         # cancel shutdown command

Save commands as batch file

Save frequently used command lines as batch file can free ourselves from typing the same words again and again. To do this, we just need to:

  1. Create a .txt file.
  2. Write some commands and save.
  3. Change the extension to .bat.

Now we have created an batch file. Double-click it and it will run as command lines in the directory of this batch file.

For Example, I created a batch file with content as

1
2
3
E:
cd E:\GitHub\mikelyou.github.io
jekyll serve

And next time when I want to launch the jekyll serve, I can simply double-click this batch file, rather than open the command line and type those long words.

References

This article is Mike Lyou’s original work and may not be reproduced without permission.


Author: Mike Lyou
Link: https://blog.mikelyou.com/2020/01/04/basic-cmd/
Liscense: This work is licensed under a CC BY-NC 4.0 International License.