Windows Command Line Basics - Windows Command Line Guide

Windows Command Line Basics - Windows Command Line Guide
Page content

Windows Command Line Commands - Understanding CLI Basics to Speed up Computer Tasks

This section deals with the most basic commands that help people new to the Windows Command Line commands use the Start Menu - Run option to speed up computer tasks. This page intends to explain the most basic features of Windows Command Line commands, mainly wildcards and paths.

CMD: While most of the Windows Command Line commands can be run directly through the RUN option under Start Menu, if you want to see the results (messages etc) as the command operates, you can get the traditional DOS-like command prompt using this command. Just type CMD in the RUN dialog box and hit Enter. Once you are there, you may use other Windows Command Line commands.

HELP: Typing HELP at the Windows Command Line gives you a list of commands supported by your copy of Windows. You can further get details on any command by typing the command name followed by a space and then “/?”. For example, if you want details about say, DIR command, you have to type it as follows:

C:\> DIR/?

Here, the “C:\>” indicates the Windows Command Line prompt where you have to type in the command. Without /?, the DIR command will show all files and folders in the root directory (indicated by \). DIR is NOT used much, as Explorer offers better views than DIR when it comes to viewing files.

Windows Command Line Commands - Using WILDCARDS

There are two wildcards that you can use when you wish to apply a command to more than one file. An asterisk (*) symbol indicates all characters in a filename or extension. The second wildcard is “?” that replaces only a single character. You can use these with ATTRIB, RENAME, DELETE, COPY, and many more commands to modify thousands of files using a single command.

Eg: ATTRIB +h *.dll will add hidden attribute to all DLL files in the specific directory.

The ATTRIB command is used to apply or remove attributes from a folder/file (see next page for details). If you wish, you can specify the first few characters of filename or extension. For example, if you save your data files as data12092009, data13092009, data14092003 and so on, you can use the wildcards with ATTRIB as follows:

ATTRIB +s data*.doc

ATTRIB +s data????????.doc

The command applies system attribute to all executables whose filename start with “data”.

Both have the same effect, though the “?” is generally substituted for fewer characters. Example: DIR data?.doc shows all files having “filename of five characters” where first four are “data” and fifth character can be anything.

Specifying Path for Certain Windows Command Line Commands

Often, you may face problems while specifying the path to a file. Almost all Windows Command Line commands are in the format commandparameters.

While in most cases, you can type in long folder names with spaces (eg Documents and Settings, Program Files), some commands assume that the space between the folder/file name is the space between parameters. To get around this, you need to remember the old DOS naming format. According to DOS file naming, a filename can be eight characters long while the extension should only be of three characters.

This means that Programs Files is Progra~1. The trick is to count the first six characters of the file or folder and append a “~” sign followed by a numeral. In cases where same filenames have same characters up to the first eight characters, you need to assign the numeral in accordance with the characters’ value. If the two files are ffilename and ffilenama then the first one will be represented as ffilen~2 while the second is ffilen~1 because “e” carries greater ASCII value than “a”.

Windows Command Line Commands - Basic, Most Useful Commands

[A] ATTRIB: While on GUI, you can right click on a file or folder to set attributes: hidden, or read-only. The GUI offers you only these two attributes. If you wish to associate system attribute or archive (handy for incremental backups), you can use ATTRIB.

The usage of this command is as follows:

C:\>Attrib **+|-**attributespath\filename.exe

The + symbol adds an attribute while the - symbol removes the attribute. You can add/remove one or more attribute to a file, a set of files, or even folders.

Example**:** ATTRIB +h +s -r C:\Windows\System32\*.ini

[B] RENAME: Used to rename a file/folder or a set of files/folders

Usage: RENAMEpath\filenamepath\new_filename

Example: Rename W*.txt to Z*.txt (renames all txt files starting with W to txt files starting with Z). Imagine achieving this using Windows GUI.

[C] DEL: Used to delete files and folder saving you time on selecting files to be deleted using GUI

Usage: DELpath\file|folder

You can use /S to direct the command to delete all subfolders too.

IMPORTANT TIP: Del c:\*.tmp /s removes all .tmp files from the C drive. I use this command very often to remove the temp and log files.

To delete files based on attributes, use /A:attribute. Example: Del d:\*.txt /s /a:-h deletes all files on D drive that do not carry the hidden attribute. If the hyphen preceding ‘h’ is removed, it deletes all files that carry the hidden attribute.

[D] DiskComp: Saves time by comparing two FLOPPY disks.

Usage: DiskComp A: B: checks for floppy disks in both drives and informs you if they both contain same data.

Example: DiskComp A: A: employs a single drive to compare two floppy disks.

DISKCOMP cannot be used for HDDs, CDs, or any network drives.

[E] FORMAT: Formats a given drive (except the system drive) with some options that are absent while formatting with GUI.

FORMAT D: **/FS:**FAT32 **/V:**data /A:1024 (Formats D drive using FAT32 file-system, assigns it the volume name “data” and takes care that each allocation unit in the file-system is equal to 1024. The /A parameter allows you to set the size of each allocation unit.)

FORMAT also lets you specify the number of tracks and sectors while used as Windows Command Line command.

Usage: FORMAT D: /T:track_num /N:sector-num.

You can add /C so that FORMAT allows compression on the drive. This can be used only when you specify NTFS with /FS.

Note that /A cannot be used along with /T

[F] IPCONFIG: Allows you to check the IP addresses of all your adaptors, flush DNS, and manually register a computer DNS - all without having to reboot the computer.

IPCONFIG, as such, displays basic IP information

IPCONFIG /ALL displays full information for all the adaptors

IPCONFIG /FLUSHDNS clears the DNS without rebooting client

IPCONFIG /RENEW “Adaptor Name” renews the DHCP IP address without having to reboot the entire network.

[G] PING: Helps you determine if your network is up. You can use PING with the IP address of any computer on the network to see if it is active. You can also check the internet connection even if you do not know the IP address of any site.

To check if your computer is able to cross the ISP gateway, use PING with website name:

PING www.google.com (sends four pings to google.com)

To send repeated pings, use /T (example: PING 198.162.11.12 /T)

When used as such, PING tries four times and informs you about the number of successful connections.

PING is especially useful when you are not sure if an Internet Connectivity problem is with ISP or local. If you can successfully Ping the ISP gateway but not any website, the problem lies locally. If PING to ISP gateway fails, it is ISP’s fault.

These are common Windows Command Line commands that help users speed up computer tasks while also helping with troubleshooting networks and Internet. The next part of the Windows Command Line Guide contains more commands for using Windows Components from Command Prompt.