Windows CLI Basics

Ajay Krishna
BeyondX
Published in
6 min readSep 19, 2020

The Command-Line Interface(CLI) lets you communicate directly with your computer and instruct it to perform various tasks. The commands are not necessarily intuitive, so they have to be learned, just like words in a language. Fortunately, there are graphical user interfaces (GUIs) replacing most procedures that formerly required using the command line.

However, a GUI does not have the same level of functionality and granular control as a command-line interface. So the CLI provides greater flexibility of use. It can be used to easily do things that are difficult or even impossible to do with a GUI.

Need for CLI

  • Do things at scale. A simple CLI command can easily adjust configurations for a large group of systems at once.
  • Something needs to be scripted and automated.
  • You need greater control over system functions.
  • Use NPM for Package Installs as Node Package Manager is easily the most popular tool for modern developers and it does not have a GUI.
  • Utilize Git Version Control.
  • For less memory usage.

Shell

Shell is a user interface responsible for processing all commands typed on CLI. It reads and interprets the commands and instructs the operating system to perform tasks as requested.

In other words, a shell is a user interface that manages CLI and acts as the man-in-the-middle, connecting users with the operating system.

Among many types of shell, the most popular ones are Windows shell (for Windows) and bash (for Linux and macOS).

Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations. PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets. Let us focus on the command shell for now!

Now the windows command shell is called “command prompt” or “cmd” in short.

Accessing the Command Prompt

  • Open Start, and type in “cmd”, and click “open”.
  • Alternatively, you can press “Windows + R” to open the run dialog box, and type in “cmd” and click “OK”.

Tips for using the cmd

  • Not case-sensitive!
  • When a file or a directory is deleted through the command line, it is not moved into the Recycle Bin.
  • If you need help with any of the command, type /? after the command.
  • When working with a file or directory with space, surround it in quotes. For example, the directory My Documents would be “My Documents” when typed.

Commands

Switch

Switches are optional extensions to a command, which change the command’s behaviour. We actually saw an example of a switch in the previous section. /? is a switch to any command, explaining its function rather than executing it in any way.

Listing the files (dir command)

Type “dir” in the cmd to list all the files in the current directory.

There are some useful switches to it. For example, with the dir command, you can type dir /p (/p being the switch) to list the files and directories in the current directory one page at a time. dir /d will list the directory contents in up to three columns. The dir command can also be used to search for specific files and directories by using wildcards. For example, to list files or directories that begin with the letter “A” you could type dir a*.

Changing directories (cd command)

After listing all the directories, we use the “cd” command. For example, by typing cd Downloads we can move into the downloads folder.

Type cd.. to return to the previous directory. To move back to the root directory type cd\ to get to the C:\> prompt.

Making a directory (mkdir command)

To create a directory in the current directory, use the mkdir command.

For example, create a directory called “test” by typing mkdir test at the prompt. If created successfully, you are returned to the prompt with no error message. After the directory is created, you can move into that directory with the cd command.

Removing a directory (rmdir command)

To remove a directory, use this command. So that would be rmdir name to remove a directory called name. Only empty directories can be removed.

Creating a new file

You can create a new file from the command line using the edit command, copy con command, or using the start command to open a file.

For example, type start notepad sample.txt to run Notepad and create myfile.txt.

Type copy con test.txt, and press Enter. Upon executing this command, the cursor moves down one line to a blank line, allowing you to create the new file line by line. Once you are ready to create the file, press Enter to get to a blank line, press and hold Ctrl, press Z, and then let go of both keys. Once ^Z is shown on the screen, press Enter to save the file and exit.

Moving/Copying files/directories

To do this, type move test.txt Downloads at the prompt. If done successfully, you get a message indicating the file was moved. You could also substitute the move command for the copy command to copy the file instead of moving it.

Renaming files/directories

After the file is moved into the Downloads directory, move into that directory with the cd command to rename the file. Type rename sample.txt first.txt at the prompt to rename the file to “first.txt.” Now, when using the dir command, you see “first.txt” as the only file.

Type rename Folder Neww to rename the Folder directory to “Neww”.

Deleting a file (del command)

It works similar to the mkdir and rmdir commands. So you type del example.exe to delete the file example.exe in your directory. If you’re not already in the right directory, you add the respective path.

Other commands

Driverquerey

For a list of all drivers installed on your system, driverquery is the quickest solution. Type “driverquery” in cmd and press Enter.

Ping

Ping must be the most popular command-line prompt. It’s used to check an IP address and see whether the respective computer is online or responding, i.e. whether network communication between your and that computer is possible.

Ipconfig

Here you can reveal network data of your own computer, such as the name of your computer in the network, your IP address, or your MAC address. Type “ipconfig” in cmd and press Enter.

--

--