In
How to Cheat at Windows System Administration Using Command Line Scripts, 2006 Now that you are familiar with different input and output command redirection techniques, let's discuss how you can group commands to create a single command line. When you group two or more commands using symbols such as &, &&, and | |, the command interpreter processes the commands either in a sequence or based on certain conditions, depending on which symbol you used. You can also group sets of commands using
parentheses. When you use commands with special symbols, the process is known as a chaining of commands. The following sections explain how to use these symbols. You can process two commands in a single command line when you separate them with an ampersand [&] symbol. Here is the syntax for using this symbol:Using Batch Files
Using Groups of
Commands
Using & for Sequential Processing
The command interpreter first processes Command 1 and then processes Command2. The following is an example of using & to process the Md and Cd commands:
This command first creates a directory named Final in the C:\Reports directory and then changes the current working directory to C:\Reports\Final.
Using && and || for Conditional Processing
When you use && between two commands in a single command line, the command interpreter processes the first command and, if successful, processes the second command. On the other hand, if you use | | between two commands, the command interpreter processes the second command only if processing of the first command failed. The syntax for using these two symbols is:
With &&, the command interpreter processes the second command only if it is successful in processing the first command. But with | |, the command interpreter processes the second command only if processing of the first command failed. Check the following examples:
In the first example, the file Rep5.txt is copied to the D:\Reports directory only if the first command is able to change the current working directory to C:\Reports\Mar98. In the second example, if the directory Mar98 does not exist, the second command is processed to create this directory.
Grouping Sets of Commands with Parentheses
You can use sets of chained commands with parentheses to form groups of command sets. The syntax is:
The command interpreter processes Command3 only if both Command1 and Command2 are executed successfully. You can reverse this condition using | | as follows:
In this case, the command interpreter processes Command2 and Command3 only if Command1 does not complete successfully.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781597491051500067
Overview of Directory Services Commands
In How to Cheat at Windows System Administration Using Command Line Scripts, 2006
DSQuery Quota
You use the DSQuery Quota command to search for quota entries for security principals in the Active Directory database according to the specified search criteria. Quota refers to the maximum number of objects that a security principal [user, group, computer, or InetOrgPerson] can own in an Active Directory partition. The syntax of this command is:
This command does not allow you to use the scope parameter for the search. You are also not allowed to use the samid option with the –o parameter. Table 10.5 explains the parameters special to the DSQuery Quota command.
Table 10.5. Parameters of the DSQuery Quota Command
{domainroot | ObjectDN} | A required parameter that specifies where the command should begin the search. You can use the domainroot option to specify the root of the current domain or you can use the ObjectDN option to specify the DN of the object. |
-acct Name | Used to search for quota specifications for the security principal [user, group, computer, or InetOrgPerson] specified by the Name option. |
-qlimit Filter | Used to search for quota specifications whose limits match the value given in the Filter option. If you want to find quota specifications that do not have any limits, you can use this parameter as –qlimit |
If the search criteria you specify do not return any results or return incorrect results, you can use the DSQuery * command. This command provides a more generalized search of the user accounts stored in the Active Directory database. For a description of common parameters, please refer to the section “Parameters Common to All DSQuery Commands,” earlier in this chapter. You can pipe the output of the DSQuery Quota command as input to other DS commands, such as DSGet, DSMove, DSMod, and DSRm.
NOTE
The command interpreter reads as a string the value specified with the –qlimit Filter parameter used with the DSQuery Quota command. You must always enclose the value of the Filter option in quotation marks. Thus, valid values for the Filter option should read as –qlimit “=100”, –qlimit ”=500”, and so on. Note that even mathematical operators, such as =, =, are to be enclosed in quotation marks. There should be no space between the mathematical operator and the numerical value.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781597491051500146
Administering Network Services
In How to Cheat at Windows System Administration Using Command Line Scripts, 2006
Overview of the NETSH Commands
The NETSH commands run within the NETSH command interpreter. To use NETSH you need to start the NETSH command interpreter from within the command prompt window, as follows:
Type NETSH at the prompt and press Enter. This will change the prompt to the netsh> context prompt. As with most Microsoft command-line utilities, typing a ? at the prompt will provide you with a list of available commands.
Commands Available within the NETSH Prompt
The NETSH command interpreter provides several subcommands for managing network services in a Windows Server 2003 environment. First, let's look at some of the internal commands that you can use within the NETSH context. Most of these commands are similar to the traditional Windows command prompt and you can use them in a similar way. Table 13.1 provides a review of these commands.
Table 13.1. List of Internal NETSH Commands
.. | Goes up one context level. |
? | Displays a list of commands. |
Abort | Discards changes made while in offline mode. |
Add | Adds a configuration entry to a list of entries. |
Alias | Adds an alias. |
Bye | Exits the program. |
Commit | Commits changes made while in offline mode. |
Delete | Deletes a configuration entry from a list of entries. |
Dump | Displays a configuration script. |
Exec | Runs a script file. |
Exit | Exits the program. |
Help | Displays a list of commands. |
Offline | Sets the current mode to offline. |
Online | Sets the current mode to online. |
Popd | Pops a context from the stack. |
Pushd | Pushes the current context onto the stack. |
Quit | Exits the program. |
Set | Updates configuration settings. |
Show | Displays information. |
Unalias | Deletes an alias. |
The following commands, when entered at the NETSH> prompt, will open a NETSH subcontext presenting you with a subcontext prompt, NETSHsub-context>.
List of Subcommands Available within the NETSH Prompt
The following is a list of the subcommands available within the NETSH prompt:
Bridge
Dhcp
Diag
Firewall
Interface
Ras
Routing
Wins
Winsock
Typing a ? or help after any of the aforementioned commands will show the subcommands for each respective subcontext command.
Master Craftsman …
If you see the words The following command was not found: “sub-context name” after entering a subcontext command at the NETSH prompt, you probably do not have the necessary helper [DLL] installed [e.g., you need to have the Dynamic Host Configuration Protocol [DHCP] installed to utilize the DHCP sub-context]. If you want to find which helpers you have installed, you can use the show helper command:
Here we see that the preceding system does not have the RAS or DHCP subcontexts available.
NOTE
Because the NETSH commands are meant primarily for managing network services running on Windows Server 2003, you cannot run these NETSH commands locally on Windows XP Professional or Windows XP Home Edition. To run these NETSH commands on a remote Windows 2000 Server, you must first use a Remote Desktop Connection to connect to a Windows 2000 Server that is running Terminal Server.
Now we'll look at some of the things you can quickly view and/or change with NETSH.
NETSH Available Information
It's easy to obtain information about available interfaces, system configurations, and the operating system from the NETSH prompt.
For instance, to obtain information about our mail configuration [Internet proxy and news client], along with operating system, modem, and network interface information, you can use the diag show all command:
The interface show interface command returns a list of available interfaces with their type and state:
Here is the output of the preceding command:
You can check the operational mode of the Windows firewall on each interface from the command line with NETSH:
The output of the preceding command is:
Now that we have taken a quick look at the basics, let's start with some troubleshooting techniques using NETSH.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781597491051500171
Using BASH
Graham Speake, in Eleventh Hour Linux+, 2010
Publisher Summary
BASH is a command interpreter that is a way for users to submit instructions to the computer. The general format of a BASH command is command-option[s] parameter[s]. There are a number of commands that helps a user to look for files. The find is very flexible, requiring a place to start, and what to look for, such as find/home-name file 1 looks for a file named “file1” in the /home directory. Anything capable of moving information in or out of Linux system has a device file in the /dev subdirectory. Block special device files move data in and out of hardware connected to the system in large chunks, and use buffers to improve efficiency, such as hard drives, USB, and tape drives. Character device files move data a single character at a time and are unbuffered. Files frequently have an extension to help indicate what they contain, which may not be so obvious, and file can sort through things with a syntax file [filename]. The ls-F command lists files with various file types tagged for easier recognition. While the file and test commands are more useful within scripts, ls-F is more helpful for humans and classifies the file with a special character denoting what it is, such as / for directory, @ for a link file, and * for an executable file.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781597494977000086
MCSE 70-293: Planning Server Roles and Server Security
Martin Grasdal, ... Dr.Thomas W. ShinderTechnical Editor, in MCSE [Exam 70-293] Study Guide, 2003
Regular Backups
It is also important to perform regular data backups. When backups are performed, the data on a computer is copied to other media [such as tape], which can then be stored in another location. If a problem occurs with the source data, you can restore any files that were damaged or lost. For example, if a user accidentally deletes a file or a server’s hard drive crashes, a backup can be restored and all files returned to their previous state.
Windows Server 2003 also provides Automated System Recovery and the Recovery Console for restoring systems that have failed.
Recovery Console is a text-mode command interpreter that can be used without starting Windows Server 2003. It allows you to access the hard disk and use commands to troubleshoot and manage problems that prevent the operating system from starting properly. With this tool, you can do the following:
■Enable and disable services.
■Format hard disks.
■Repair the master boot record and boot sector.
■Read and write data on FAT16, FAT32, and NTFS drives.
■Perform other tasks necessary to repairing the system.
You can start Recovery Console from the installation CD for Windows Server 2003, or you can install it on an x86-based computer. When installed on the computer, Recovery Console can be run from a multiple-boot menu that appears when the computer is first started. Either method will start the same program and allow you to enter different commands to repair the system.
Automated System Recovery [ASR] allows you to back up and restore the Registry, boot files, and other system state data, as well as other data used by the operating system. An ASR set consists of files that are needed to restore Windows Server 2003 if the system cannot be started. When you create an ASR set, the following items are backed up:
■System state data
■System services
■Disks that hold operating system components
In addition, ASR creates a floppy disk that contains system settings. Because an ASR set focuses on the files needed to restore the system, data files are not included in the backup.
You should create an ASR set each time a major hardware change or a change to the operating system is made on the computer running Windows Server 2003. For example, if you install a new hard disk or network card, or apply a security patch or service pack, you should create an ASR set. Then, if a problem occurs after upgrading the system, you can use the ASR set to restore the system to its previous state [but only after you’ve attempted other methods of system recovery].
ASR should not be used as the first step in recovering an operating system. In fact, Microsoft recommends that it be the last possible option for system recovery and be used only after you’ve attempted other methods. In many cases, you’ll be able to get back into the system using Safe Mode, the Last Known Good Configuration or other options.
To create an ASR set, use the Windows Server 2003 Backup utility. On the Welcome tab of the Backup utility, click the Automated System Recovery Wizard button. This starts the Automated System Recovery Preparation Wizard, which takes you through the steps of backing up the system files needed to recover Windows Server 2003 and creating a floppy disk containing the information needed to restore the system.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781931836937500063
Locking Down Your XenApp Server
Tariq Bin Azad, in Securing Citrix Presentation Server in the Enterprise, 2008
Installing and Using the Recovery Console
The Recovery Console is a text-mode command interpreter that can be used without starting Windows Server 2003. It enables you to access the hard disk and use commands to troubleshoot and manage problems that prevent the operating system from starting properly. With this tool, you can do the following:
▪Enable and disable services
▪Format hard disks
▪Repair the master boot record and boot sector
▪Read and write data on FAT16, FAT32, and NTFS drives
▪Perform other tasks necessary to repairing the system
The Recovery Console can be started from the installation CD for Windows Server 2003, or you can install it on an x86-based computer. When installed on the computer, you can run it from a multiple-boot menu that appears when the computer is first started. Either method starts the same program and enables you to enter different commands to repair the system.
Note
You cannot install the Recovery Console on an Itanium running the 64-bit version of Windows Server 2003. You can still access the Recovery Console from the CD.
Configuring & Implementing…
Installing and Using the Recovery Console
Here is a brief step-by-step exercise for installing the Windows 2003 Recovery Console. To start the Recovery Console from the installation CD, run Windows Server 2003 Setup. Press Enter on your keyboard when the Setup Notification screen appears, and then press R on your keyboard to select the option of repairing the installation. This opens the Recovery Console and enables you to enter commands at the prompt.
To install the Recovery Console as a startup option, follow these steps:
1Ensure that the Windows Server 2003 CD is in the CD-ROM drive.
2Click Start | Run.
3Enter the drive letter of your CD-ROM drive, then type /I386/Winnt32.exe /cmdcons.
4A message box appears, asking if you'd like to install Recovery Console as a startup option and telling you that it takes approximately 7MB of disk space. Click Yes.
5Windows Setup starts and the Recovery Console is installed.
Upon restarting your computer, you see a multiboot menu that enables you to start different operating systems installed on the computer. On this menu, you also see an option labeled Microsoft Windows Recovery Console. Select it to highlight it and press Enter on your keyboard to start the Recovery Console.
When the Recovery Console starts, you must select the Windows installation you'd like to log onto, and enter the password for the Administrator account for that installation. The built-in Administrator account is the only account you can use to run the Recovery Console on Windows Server 2003.
The Recovery Console provides a prompt where you can enter text-based commands. The commands available to you are shown in Table 7.2.
Table 7.2. Commands for Recovery Console
ATTRIB | Enables you to view and change attributes on a file or directory |
BATCH | Executes commands in a text file |
BOOTCFG | Used for boot configuration and recovery. Enables you to scan disks for Windows installations, add an installation of Windows to the boot list, set the default boot entry, list entries in the boot list, and configure other parameters related to boot configuration. |
CD | Displays the name of the current directory and enables you to change to a new directory |
CHDIR | Displays the name of the current directory and enables you to change to a new directory |
CHKDSK | Checks the disk for errors and displays results |
CLS | Clears the screen |
COPY | Copies a file to another location |
DEL | Deletes a file |
DELETE | Deletes a file |
DIR | Displays the contents of a directory |
DISABLE | Disables a service |
DISKPART | Used to manage partitions on a hard disk. Enables you to add and delete partitions. |
ENABLE | Enables a service |
EXIT | Exits the Recovery Console and restarts the computer |
EXPAND | Expands a compressed file |
FIXBOOT | Creates a new boot sector on the system partition |
FIXMBR | Used to repair the master boot record on the boot partition |
FORMAT | Formats a disk |
HELP | Displays commands available to use in the Recovery Console |
LISTSVC | Lists available services and drivers |
LOGON | Enables you to log on to an installation of Windows |
MAP | Displays a list of drive letter mappings |
MD | Creates a new directory |
MKDIR | Creates a new directory |
MORE | Displays a text file on the screen |
RD | Deletes a directory |
REN | Renames a file |
RENAME | Renames a file |
RMDIR | Deletes a directory |
SYSTEMROOT | Sets the current directory to the systemroot |
TYPE | Displays a text file on the screen |
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B978159749281200007X
Linux
Bryan Pfaffenberger, in Encyclopedia of Information Systems, 2003
III.C.2. Shell
The second major component of Linux is the shell, which functions as a command interpreter. Although Linux enables users to select the shell of their choice, by far the most widely used shell is the GNU Project's Bourne Again Shell [bash]. The shell runs in text mode; if X is running, it runs in a terminal window.
The bash shell is a fully programmable shell with many advanced features, including aliases, job control, filename completion, command history, shell functions, and much more. Although difficult to learn and use, it provides a powerful environment for executing text-mode programs and scripts.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B0122272404001052
Operating Systems
Yao-Nan Lien, in The Electrical Engineering Handbook, 2005
4.2.4 Shell: Command-Based User Interface
A user can interact with the operating system through a special process, the command interpreter using a command language. A command language can be either very simple in the early days or as powerful as a regular programming language. Most UNIX systems offer one or more command interpreter with a name called shell or its variations. Unfortunately, the term shell may cause some confusion because it is also used by researchers as a generic term to denote the layer of software for users to interact with an operating system. When any user logs in, a shell is started up. The shell has the terminal as standard input and standard output. It starts out by displaying a prompt symbol, such as a dollar sign, indicating that it is waiting to accept a command. For example, if the user types:
who,
the shell creates a child process and runs the who program as the child. The shell is waiting until the child process is terminated. When the child finishes, the shell displays the prompt again and waits for the next command.
UNIX's shell offers a regular programming capability to its users such that its users can request very rich services from the operating system. In addition to the common flow control constructs, shell offers several unique features: I/O redirection, pipelining, and background job execution.
A user can specify standard output to be redirected to a file by typing, for example:
who>outfile.
Similarly, standard input can be redirected from another file, as in:
sortoutfile ,
which invokes the sort program with input taken from file infile and output sent to outfile.
The output of one program can be used as the input for another program by connecting them with a pipe. Thus, the command:
who|wc> dev/tty10
invokes the who program to list all users currently logged in the system and sends the output to wc to count the number of entries. The output of wc is redirected to a file, /dev/tty10 which by convention is a special file denoting a terminal.
If a user put an ampersand after a command, the shell does not wait for it to complete. Instead it just gives a prompt immediately. For instance, the command:
ccfile.c&
starts up a compiling job in the background, allowing the user to continue working as the compiler is running.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B978012170960050030X
Managing Files and Directories
In How to Cheat at Windows System Administration Using Command Line Scripts, 2006
Duplicating and Comparing Disks
It's easy to duplicate floppy disks using the Diskcopy command; then you can compare the copied disk to the original disk using the Diskcomp command [covered shortly]. Diskcopy is particularly useful when you want to make copies of a particular disk for distribution. The disks can be made bootable for starting up new computers that do not have any operating systems installed. The commands work even if you have only a single floppy disk drive in your computer. They are explained in the following sections.
Duplicating Disks with the Diskcopy Command
You can use the Diskcopy command to copy files and folders from one disk to another. This command works only with removable disks [such as floppy disks]. You cannot specify any hard disk as the source or destination drive. The syntax of this command is:
Drive1 is the source drive and Drive2 is the destination drive. These drives are usually assigned the letter A or B. The destination disk may be formatted or unformatted. If you do not use the destination drive parameter, the source drive is used as the destination drive as well. In this case, you will be prompted to insert a different floppy disk, which will be treated as the destination drive. You use the /v parameter to verify the file copy operation by comparing files as they are copied. Use of this parameter slows down the file copy process.
When you use the Diskcopy command to specify the source and destination drives, the command interpreter prompts you to insert both of the disks. The following example shows how you can use the command to copy a disk in drive A: to drive B:
You are prompted to insert the source disk first, as follows:
When you insert the disks in the specified drives, the data is copied from the source disk to the destination disk track by track. When the copy operation is completed, you are asked whether you want to copy another disk:
If you want to copy more disks, press the Y key. Otherwise, press the N key to stop the copy operation.
If you have only one floppy disk drive on your computer, you can omit the source and destination drive letters with the Diskcopy command. However, your current working drive should be one of the hard-disk drives, such as the C: drive. You can use this option with most of the newer computers that come with just one floppy drive. In this case, the command interpreter treats the same drive as the source and the destination. You will need to switch to the C: drive and then use the following syntax for the Diskcopy command:
The command will prompt you for the source disk and then the destination disk in the same disk drive. If your computer does not have sufficient physical memory [RAM], the computer will first copy a portion of the source disk to the destination disk, and then prompt you for the source disk to complete the copy process.
When you insert an unformatted disk in the destination drive, the Diskcopy command formats the disk in exactly the same format as the source disk. The following message is displayed on the screen:
When the copy process is complete, you are asked whether you want to copy another disk.
The Diskcopy command has its own set of exit codes, which you can use in batch files with the if and goto commands set with the Errorlevel parameter to perform conditional processing of the file. Table 4.9 lists the exit codes for this command.
Table 4.9. Exit Codes for Use with the Diskcopy Command
0 | The command completed successfully. No error was encountered. |
1 | The command encountered a nonfatal read/write error. |
3 | The command encountered a fatal hardware error. |
4 | The command encountered an initialization error. |
When you have two floppy disks with different formats and you want to copy the files and directories from one floppy to the other, you should use the Xcopy command rather than the Diskcopy command. This is because the Diskcopy command copies data from one disk to another by reading each track from the source disk and copying it to the destination disk. If the two disks are not identically formatted, the use of the Diskcopy command may result in errors. Xcopy does not have any such requirement. Use Diskcopy when you need to copy images from one disk onto other identically formatted disks. Another limitation of the Diskcopy command is that if the source disk is fragmented, the fragmentation gets copied to the destination disk. But the Xcopy command has a limitation as well: You cannot use it to make bootable disks.
Comparing Two Disks with the Diskcomp Command
You can compare data in two floppy disks using the Diskcomp command. This command works specifically with floppy disks. You cannot use this command to compare the contents of two hard disks or two hard-disk partitions. It does not matter whether you have a single floppy disk drive or two drives; the command works the same way. You will be prompted to insert the appropriate floppy disks when you use the command. The syntax of the command is:
The Drive1 and Drive2 parameters specify the two disks you want to compare. You can use either a single disk drive or two separate drives for comparison. If you are using a single disk drive, the command interpreter prompts you for the first and second disks, one by one. You use the following command syntax for computers with a single drive:
If your computer does not have enough physical memory [RAM] available, you may be prompted for the disks more than once [depending on the amount of available memory]. This is because the computer copies the contents of one disk into memory and then compares it with the contents of the second disk. When working with a single disk drive, you can omit the Drive2 parameter or both Drive1 and Drive2 parameters. You will be prompted to insert disks as required. The following two commands have the same functionality when working with single drives:
When you compare two identical disks by using either the same disk drive [A:] or two different drives [A: and B:], the following message is displayed:
You can insert another disk to compare with the first, or press the N key to exit. If the two disks do not have identical contents, a message similar to the following is displayed:
Now, let's see what happens when you try to compare the contents of a removable disk with those of a fixed disk. In the following example, we will try to compare floppy disk A: with the contents of drive D:, where the D: drive is a hard-disk partition:
You will get the following error message:
Like other commands, Diskcomp has a set of exit codes which you can use in batch or script files for performing conditional processing. You use the exit codes with Errorlevel statements for decision making, along with the if and goto parameters. Table 4.10 lists the exit codes for the Diskcomp command.
Table 4.10. Exit Codes for Use with the Diskcomp Command
0 | Compared disks are the same and have identical data. |
1 | The command found differences in two disks. |
3 | The command encountered some hardware-related error. |
4 | There was some initialization error. |
NOTE
When comparing two floppy disks, the Diskcomp command can compare only identical ones. This means that you cannot compare the contents of a single-sided disk with a double-sided disk. If you try to perform the comparison, the command interpreter displays the following error message:
Drive types or diskette types not compatible.
The same message will be displayed if you compare a double-density disk with a high-density disk.
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781597491051500080
Basics of the Command Line
In How to Cheat at Windows System Administration Using Command Line Scripts, 2006
Starting the Windows Command Shell
The first step in learning to work with command-line utilities is to determine the different methods you can use to start the Windows command shell. The Windows command shell, in turn, starts the command interpreter.
The Windows command shell is actually an application built into the Windows operating system. CMD.exe is the command interpreter that accepts your commands and executes them in the way you want. You can access the Windows command shell in one of the following ways:
▪Click Start | Run and type cmd in the Open field of the Run dialog box. Click OK or press Enter.
▪Click Start | Programs | Accessories and click Command Prompt.
Either of the aforementioned actions will open the Windows command interpreter and provide you with a 32-bit environment for executing commands. You can also place a shortcut for the command prompt on your desktop if you will be using it often. Figure 1.1 shows the command shell.
Figure 1.1. The Windows Command Shell
The command interpreter executable, CMD.exe, is placed in the %SystemRoot%\System 32 folder. In Windows XP, the command shell window title will read C:\Windows\System32\CMD.exe, and in Windows 2003, it will simply read Command Prompt. By default, the command shell starts in the user profile folder of the currently logged on user. That's why the current working directory is shown as C:\Documents and Settings\Administrator in Figure 1.1.
A blinking cursor following the command prompt indicates that it is in interactive mode. This mode allows you to enter commands directly at the prompt and press the Enter key to execute them. For example, if you type the command Dir at the command prompt and press the Enter key, the command will execute immediately and the results will appear in the window. You can also write a series of commands and save them as a batch file. When the batch file is executed, the command interpreter reads the commands, one line at a time, and executes them in order. You can also group multiple commands in a single command line and process them sequentially. We discuss these techniques, along with the basics of batch files, in Chapter 2.
Customizing the Command Shell Startup
As we discussed earlier, you can start the command shell either from the Run dialog box or from Accessories in the Programs menu. This starts the command interpreter in its default mode. You can customize the default behavior of the CMD.exe interpreter using a number of available parameters or switches. Changing the defaults affects the applications or other commands you run inside the command shell. For example, you can configure the command prompt to execute a string of commands and then exit interpreter mode by typing Cmd /c in the Run dialog box, or you can type Cmd /q to turn off echo, which is enabled by default.
The syntax for CMD.exe is:
Table 1.1 explains the switches for the cmd.exe command.
Table 1.1. CMD.exe Parameters for Setting the Command Shell Working Environment
/C string | Executes the command specified in the string and then exits the command shell. |
/K string | Executes the command specified in the string and does not exit the command shell. |
/S | Modifies the commands used as strings with the /C and /K parameters. Usually, you place quotes around command strings. The /S parameter removes the opening and closing quotes before processing the command. |
/A | Causes the output of internal commands to be sent to a file [this process is also called piping] in ANSI character format. |
/U | Causes the output of internal commands to be sent to a file [this process is also called piping] in Unicode character format. |
/Q | Turns off echo, which is on by default. Echo off mode is also known as quiet mode. When echo is on, each command is displayed as it is processed. |
/D | Disables the AutoRun command from the Registry. |
/E:ON | Enables command extensions if they were disabled. Command extensions are enabled by default. |
/E:OFF | Disables command extensions. |
/F:ON | Enables the completion of characters for files and directories, which help improve typing speed at the command prompt. |
/F:OFF | Disables the completion of characters for files and directories. |
/V:ON | Enables delayed environment variable expansion by using the exclamation point character [!] as the delimiter. This means that using !ThisVar! will expand the variable ThisVar at the time of execution. |
/V:OFF | Disables delayed environment variable expansion. |
/T:FG | Sets the foreground and background colors. The F and G represent color values. They must be used without spaces. |
From Table 1.1, it is clear that you cannot use some variables together. For example, if you are using /A, you cannot use /U at the same time. Similarly, you can use either /E:ON or /E.OFF. Besides this, several parameters are set by default when you start the command shell.
Master Craftsman …
The commands you use at the command prompt in Windows are not case sensitive. You do not have to worry about the Caps Lock key when you are typing commands. This means that DelTree.exe, DELTREE.exe, and deltree.exe have the same meaning. We have used upper- and lowercase in this book just to increase the clarity and readability of the commands. You might find this to be different from UNIX and Linux environments, where commands are case sensitive.
You also may have noticed in Table 1.1 the function of the /S parameter that modifies the strings when using the /C or /K parameter. The /S parameter removes the quotation marks from the beginning and end of the command. The quotation marks are preserved only if all of the following conditions are met:
▪You are not using the /S switch.
▪There is exactly one set of quotation marks.
▪There are no special characters, such as &, , [, ], @, and ⁁, between two quotation marks.
▪There are one or more spaces between the quotations marks.
▪The string is the name of an executable file.
If any of these conditions are not met, the /S switch removes the opening and closing quotes.
You use the /T:FB switch to set the colors of the command shell. Table 1.2 provides the values of these colors.
Table 1.2. Color Values for the Command Shell
0 | Black |
1 | Blue |
2 | Green |
3 | Aqua |
4 | Red |
5 | Purple |
6 | Yellow |
7 | White |
8 | Gray |
9 | Light blue |
A | Light green |
B | Light aqua |
C | Light red |
D | Light purple |
E | Light yellow |
F | Bright white |
Customizing the Command Shell Window
The command prompt window shown in Figure 1.1 has several properties that you can configure to customize your working environment. For example, the window is 80 characters wide and is 25 lines long by default. The characters are displayed in white over a black background. You can set the cursor size, fonts, colors, and number of commands in the command history, and whether the command shell should use a small window or the full screen.
To change the default settings of the command shell, right-click the command icon in the top-left corner of the window and select Properties from the menu. The following sections explain the settings in each tab in this window.
The Options tab allows you to set the cursor size, command history, display options, and editing options, as shown in Figure 1.2. You can choose from small, medium, or large cursor sizes. You use the Command History portion to set the number of commands that the command interpreter can remember. The number of buffers indicates how many separate histories are maintained. The larger the number of commands you keep in the history, the more memory you will need. By default, there are four buffers and each buffer stores 50 commands.
Figure 1.2. The Options Tab in the Command Shell Properties Window
You can set these numbers at anywhere from zero to 999. If you are not sure how many buffers you will need, you should not change this setting. You can choose to discard duplicate commands in the history to avoid unnecessarily filling up the buffer by repeating the same command.
You can use Quick Edit Mode or Insert Mode when editing commands. Use Quick Edit Mode when you want to use the mouse to edit entries. Insert Mode works by inserting text without overwriting the existing text in a line. For example, if you want to copy a line from another application and paste it directly into the command line, you can use Insert Mode.
The Font tab allows you to choose a font and its size, as shown in Figure 1.3. These options let you control the size of the text within the command shell. The default font is 12-point Lucida Console. With Raster fonts the size of the window automatically changes when you change the font size. You can also make the fonts appear in boldface.
Figure 1.3. The Font Tab in the Command Shell Properties Window
You can change the layout of the command shell window from the Layout tab, as shown in Figure 1.4. The screen buffer size affects the size of the window and is set at 80 × 300 by default. A smaller screen buffer size lets you scroll through the window so that you can check previously used commands and their outputs. Some scripts require a large screen buffer, but a buffer setting of 1,000 by 1,500 would suffice in most cases. The combination of screen buffer size and window height lets you view the executed commands easily and scroll up and down the command shell window. You can also set the window position to any corner of the screen, or let Windows manage the position automatically.
Figure 1.4. The Layout Tab in the Command Shell Properties Window
The Colors tab, shown in Figure 1.5, allows you to customize the colors of the command shell. You can set the background and the text foreground to the color of your choice. You can also set the background and text colors for pop-up windows. Usually, you select the colors from the color bar and the resulting window is displayed at the bottom so that you can see how the command shell window will look after the changes take effect. By changing the values of the red, green, and blue colors, you can fine-tune the selected color. These values range from zero to 255 for each color.
Figure 1.5. The Colors Tab in the Command Shell Properties Window
When you finish changing the properties of the command shell, click OK. A small Apply Properties dialog box will prompt you to select how the changes should take effect. This is shown in Figure 1.6. You can choose to apply the changes to the current window only, or save the settings for future windows with the same title. If you select the second option, the changes will apply to all command shell windows that you open in the future. If you have placed a shortcut for the command prompt on the desktop or in the Start menu, the second option changes to “Modify shortcut that started this window” and every time you start the command prompt from that shortcut, the changes will take effect.
Figure 1.6. Applying Changes to Command Shell Window Properties
Read full chapter
URL: //www.sciencedirect.com/science/article/pii/B9781597491051500055