Sunday, July 9, 2017

Windows Command Line Interface - An Introduction

Getting this blog off the ground has been a challenge. I went for over two years without a post. In an effort to make it work, my goal will be to have a new post each Sunday evening. I'll do my best to come up with useful topics for each post. Since there are no less than three currently in-use Windows operating systems, I'll try to include articles about each (Windows 7, Windows 8 / 8.1, and Windows 10). If you have questions, or recommendations for topics, please send me an email or leave a comment.

Now, on with the show . . . .



Long before Windows and it's graphical user interface (GUI), really smart people used a command line interface to operate computers. One of the most popular, most profitable, and most widely-known operating systems in those days was the Microsoft Disk Operating System, more commonly known as MS-DOS. Early users and administrators of business and home computers are probably still familiar with MS-DOS. I know people who still prefer to use the Command Line Interface (CLI) and PowerShell whenever possible to manage servers.


(Side note: I realized that I was a computer geek in the early 90's when I would BS with friends about MS-DOS, Windows, and computers in general. They still make me look like a n00b.) 

Here's a really short version of the evolution of MS-DOS and Windows (not all-inclusive):
  • August 1981 - MS-DOS was officially released; its market base grew significantly because it was commonly installed on IBM-compatible PCs by the manufacturer and sold as the OEM OS.
  • November 1985 - MS Windows 1.0 released. MS-DOS was the disk operating system; Windows was the operating environment that ran on DOS and used a framed graphical user interface (GUI) for users to access files and programs. The framed GUI made it easier and more popular for average people to use computers because they didn't have to be proficient with the DOS CLI. Windows 3.0, released in May 1990, was the first experience many users had with computers. It gave MS a major foothold in the growing PC industry.
  • August 1995 - Windows 95 released; the paradigm was reversed: Win95 was the OS and the CLI became a management application within the Windows OS; all subsequent versions of Windows use this model.
  • September 2000 - MS-DOS 8 released; final version of stand-alone MS-DOS.
(Check this page out or a more detailed history of the MS Windows OS: The History of Windows Operating Systems.)

This post isn't intended to spark debate about which disk operating system was first or which one is best. Nor is it intended to provide a full-blown course on the CLI. My intent is to address some of the more commonly-used CLI commands. All of these commands can be used by casual and novice users without fear of damaging anything. None of these commands will change anything on your computer. These commands will either help you navigate via the CLI, or will provide you with information about your computer.


The easiest way to launch the CLI is to click on your Start button and type "cmd" into the "Run" box and press <Enter>. This will launch the CLI using your current logon as the operator. There may be access limitations if you're not logged on as a local administrator. The default directory will be your home directory / folder as shown below:




Another easy way to launch the CLI is to click Start menu button and type "cmd" into the "Search" box. Right-click on "Command Prompt" and then left-click on "Run as administrator". That will allow you run the CLI with elevated permissions. The "home" directory for launching the CLI this way is "C:\WINDOWS\system32" and shown here:




In both cases, the OS name, version, and copyright are displayed on the first two lines of the CLI. If you type "winver", and then press <Enter>, you'll see a pop-up like below that provides all the necessary info about your OS. As you can see, I'm running Windows 8. But if you read further, you'll see that I'm specifically running Windows 8.1 Pro with Media Center and that it's version 6.3:





The redacted line is just the email account that the OS is registered to that I used to log into my laptop.

I originally started writing this post in February 2015. I upgraded my laptop 3 times since then and am now running Windows 10 Creators Update.




Here are several more useful CLI command. Unlike some of the CLI commands for Linux and Unix OSes, these commands are not case-sensitive. I typed them in all caps for emphasis.

WMIC BIOS GET SERIALNUMBER should show you the serial number for your computer as embedded in the BIOS (Basic Input/Output System), which is the firmware programs that boots your computer prior to the operating system launching. It SHOULD match the serial number on the label on the back or bottom of your computer.

CHDIR displays or changes the current working directory. This should match the path listed in the command prompt itself.

DIR lists the contents (folders and files) of a folder.

DIR /P will list the contents of the current working folder, but will pause after a certain number of items and prompt you to press any key when you wish to proceed.

CD changes directory.

CD .. (cd, space, two periods). navigates up one folder level.

CD\ (cd backslash) navigates from the current directory to the root of the current drive.

CD USERS changes from the root of the c: drive to the users folder. This is where the user profile folders are stored for that computer. Each user that has logged on to that computer with a unique username will have a user profile folder. Once in this folder, you can run the DIR command to see a list of other user folders. You can CD into the folder with your user name, run the DIR command again, and see folder such as "Documents", "Downloads", "Music", etc. The names may vary slightly depending on which version of Windows you're running.

<drive letter>: (ex: x:) changes from the current working drive to the specified drive letter. In this example, the command X: changes from the C: drive to the X: drive, which is one of my external hard drives (HDDs). The command C: changes from the X: drive back to the C: drive in the working directory that I had last navigated to.



CLS clears the terminal screen returning it to a blank screen with only a command prompt showing.

CHKDSK is a diagnostic command that scans the specified HDD for various errors, and usually fixes them. You can use the command to scan attached HDDs without rebooting; however, if you run the CHKDSK on the C: drive, it will tell you that the scan will have to be performed during the next system reboot.

SCANDISK is an older version of CHKDSK from Windows 95 and 98 (Win9x) and works similarly.

IPCONFIG displays the basic network configuration of your computer.


IPCONFIG /? displays the usage and syntax of the IPCONFIG command. /? can put placed after most base commands to see their usage and syntax.


IPCONFIG /ALL displays more detailed network configuration information.


IPCONFIG /ALL > IPCONFIG.txt sends the output to a text file named "IPCONFIG.txt" in the folder where your CLI command prompt is currently located.


ROUTE PRINT displays the basic routing information stored in your computer.


ROUTE PRINT >> IPCONFIG.txt appends the ROUTE PRINT output to the "IPCONFIG.txt" file without overwriting the IPCONFIG output.


PING sends a test signal out to an IP address, computer name, or Internet URL. Used to troubleshoot possible network connectivity issues. Ex: ping www.google.com.


TRACERT (trace route) is used similarly to the PING command to show the route "hops" taken from your computer to the destination device. The base command is followed by an IP address, computer name, or Internet URL. Ex: tracert www.google.com.


Here you can see and compare the results of the ping and tracert to www.google.com. The time outs are servers that probably have Internet Control Message Protocol (ICMP)  disabled so they're not returning a ping response.



NETSTAT displays protocol statistics and current TCP/IP network connections.


NSLOOKUP [comptuername] queries local DNS and returns the IP address currently assigned to the identified computer. All computers computer maintain a local DNS cache of other computers that they've communicated with, but this command really only works if your computers is in a domain and you're looking up other computers in that same domain.


NSLOOKUP [web address] queries external DNS (usually web-based) to return the IP address for the specified web address / URL.


Sources:

Books:


Windows Command-Line Administrator's Pocket Consultant, 2nd Edition - I used this one while attending Capital Area Technical College and still use it occasionally.

Windows PowerShell 2.0 Administrators Pocket Consultant - I used this one while attending Capital Area Technical College, but don't use it as often. I'm lazy and prefer to use the GUIs when possible.

Web Sites:

MS-DOS overview - Microsoft's official MS-DOS page as it relates to WinXP.


MS-DOS - Wikipedia article on MS-DOS



Microsoft Windows - Wikipedia article on the history and evolution of MS Windows.

List of DOS commands - Wikipedia article on common MS-DOS commands; the use of the commands is explained, but not so much the proper syntax.



DOS Commands: A Complete List of MS-DOS Commands - A much more thorough reference for MS-DOS commands, usage, and proper syntax.

15 CMD Commands Every Windows User Needs To Know.


18 Useful Command Prompt Tricks You Might Not Know