Tag Archives: command prompt; command line; cmd.exe; DOS

Pushd

The Pushd command stores the current directory for use by the popd command, and then changes to the specified directory. The popd command changes the current directory to the directory that was most recently stored by the pushd command

Syntax (view syntax formatting guide):

pushd [<Path>]

Syntax Explanation

 

  • <Path>: Specifies the directory to make the current directory. This command supports relative paths.
  • /?: Displays help at the command prompt.

Every time you use the pushd command, a single directory is stored for your use. However, you can store multiple directories by using the pushd command multiple times.
The directories are stored sequentially in a virtual stack. If you use the pushd command once, the directory in which you use the command is placed at the bottom of the stack. If you use the command again, the second directory is placed on top of the first one. The process repeats every time you use the pushd command.
You can use the popd command to change the current directory to the directory most recently stored by the pushd command. If you use the popd command, the directory on the top of the stack is removed from the stack and the current directory is changed to that directory. If you use the popd command again, the next directory on the stack is removed.

If command extensions are enabled, the pushd command accepts either a network path or a local drive letter and path.

If you specify a network path, the pushd command temporarily assigns the highest unused drive letter (starting with Z:) to the specified network resource. The command then changes the current drive and directory to the specified directory on the newly assigned drive. If you use the popd command with command extensions enabled, the popd command removes the drive-letter assignation created by pushd.

Explanation with Examples

The following example shows how you can use the pushd command and the popd command in a batch program to change the current directory from the one in which the batch program was run and then change it back:

@echo off
rem This batch file deletes all .txt files in a specified directory
pushd %1
del *.txt
popd
cls
echo All text files deleted in the %1 directory


 

Prompt

The Prompt command changes the Cmd.exe command prompt. If used without parameters, prompt resets the command prompt to the default setting, which is the current drive letter and directory followed by the greater than symbol (>). A command prompt (or just prompt) is a sequence of (one or more) characters used in the  command-line interface to indicate readiness to accept commands. By using any of the set of character combinations listed belown the command-prompt can be modifiable by the user. Depending on the environment, a user may be able customize the command-prompt by changing the color, adding special character that may be conducive to their liking or perhaps adding the current time, all to make the prompt more informative or visually pleasing.

Syntax (view syntax formatting guide):

prompt [<Text>]

Syntax Explanation

  • Text: Specifies the text and information that you want to include in the command prompt.
  • /?: Displays help at the command prompt.

You can customize the command prompt to display any text you want, including such information as the name of the current directory, the time and date, and the Microsoft Windows version number.

The following is a list of character combinations that you can include instead of, or in addition to, one or more character strings in the Text parameter. The list includes a brief description of the text or information that each character combination adds to your command prompt. 


  • $q: = (equal sign)
  • $$: $ (dollar sign)
  • $t: Current time
  • $d: Current date
  • $p: Current drive and path
  • $v: Windows version number
  • $n: Current drive
  • $g: > (greater than sign)
  • $l: < (less than sign)
  • $b: | (pipe)
  • $_: ENTER-LINEFEED
  • $e: ANSI escape code (code 27)
  • $h: Backspace (to delete a character that has been written to the command line)
  • $a: & (ampersand)
  • $c: ( (left parenthesis)
  • $f: ) (right parenthesis)
  • $s: space

NOTE: When command extensions are enabled (that is, the default) the prompt command supports the following formatting characters:

  • $+: Zero or more plus sign (+) characters, depending on the depth of the pushd directory stack (one character for each level pushed).
  • $m: The remote name associated with the current drive letter or the empty string if current drive is not a network drive.

NOTE: If you include the $p character in the text parameter, your disk is read after you enter each command (to determine the current drive and path). This can take extra time, especially for floppy disk drives.

Explanation with Examples

To set a two-line command prompt with the current time and date on the first line and the greater than sign on the next line, type:

prompt $d$s$s$t$_$g

The prompt is changed as follows, where the date and time are current:

Fri 06/01/2007  13:53:28.91

>

To set the command prompt to display as an arrow (–>), type:

prompt –$g

To manually change the command prompt to the default setting (the current drive and path followed by the greater than sign), type:

prompt $p$g

 

Popd

The popd command changes the current directory to the directory that was most recently stored by the pushd command. The pushd command saves the current working directory in memory so it can be returned to at any time.

Syntax (view syntax formatting guide):

popd

Syntax Explanation

  • /?: Displays help at the command prompt.

Every time you use the pushd command, a single directory is stored for your use. However, you can store multiple directories by using the pushd command multiple times.
The directories are stored sequentially in a virtual stack. If you use the pushd command once, the directory in which you use the command is placed at the bottom of the stack. If you use the command again, the second directory is placed on top of the first one. The process repeats every time you use the pushd command.
You can use the popd command to change the current directory to the directory most recently stored by the pushd command. If you use the popd command, the directory on the top of the stack is removed from the stack and the current directory is changed to that directory. If you use the popd command again, the next directory on the stack is removed.

When command extensions are enabled, the popd command removes any drive-letter assignations created by pushd.

Explanation with Examples

The following example shows how you can use the pushd command and the popd command to save and return to a current working directory:

C:usersTom>pushd /

C:>pobd

C:userTom>

 

Perfmon

The Perfmon command allows you to start the Windows Reliability and Performance Monitor in a specific standalone mode. Perfmon, also known as “Performance Monitor”, got its roots as a command called, “sysmon.exe” in Windows 95, 98 and XP. The perfmon command is used to view information about a systems; CPU, Disk, Network and Memory statistics.

Syntax (view syntax formatting guide):

perfmon </res|report|rel|sys>

Syntax Explanation

  • /res: Start Resource View.
  • /report: Start the System Diagnostics Data Collector Set and display a report of the results.
  • /rel: Start Reliability Monitor.
  • /sys: Start Performance Monitor.

Explanation with Examples

To view the performance monitor in a standalone view:

c:perfmon

To view the resource monitor in a standalone view:

c:perfmon /res

To view the reliability monitor built into Windows Vista and 7:

c:perfmon /rel

 

Pause

The Pause command suspends the processing of a batch program and displays the following prompt:

Press any key to continue . . .

This is beneficial in case you do not wish to complete the batch program or perhaps you need to give the user a chance to insert a new disk into the drive before continuing the batch.

Syntax (view syntax formatting guide):

pause

Syntax Explanation

  • /?: Displays help at the command prompt.

When you run the pause command, the following message appears: 


Press any key to continue . . .

If you press CTRL+C to stop a batch program, the following message appears: 


Terminate batch job (Y/N)?


If you press Y (for yes) in response to this message, the batch program ends and control returns to the operating system.

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.

Explanation with Examples

To create a batch program that prompts the user to change disks in one of the drives:

@echo off
:Begin
copy a:*.*
echo Put a new disk into drive A
pause
goto begin

In this example, all the files on the disk in drive A are copied to the current directory. After the message prompts you to put a new disk in drive A, the pause command suspends processing so that you can change disks and then press any key to resume processing. This batch program runs in an endless loop—the goto begin command sends the command interpreter to the Begin label of the batch file. To stop this batch program, press CTRL+C and then press Y.