Tag Archives: command line syntax

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


 

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>

 

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.

 

Syntax Formatting Guide for WindowsCommandLine.com

This document is a guide to the syntax representations shown here at WindowsCommandLine.com. It is intended to help you understand the syntax shown for each command.

The following example syntax statement, taken from the icacls command,  will be used to explain the  syntax elements you may see for a command:

icacls FileName [/grant[:r] Sid:<Perm>[...]] [/deny Sid:Perm[...]]
 [/remove[:g|:d]] Sid[...]] [/t] [/c] [/l] [/q]
 [/setintegritylevel Level:Policy[...]]

OR

icacls Directory [/substitute SidOld SidNew [...]]
 [/restore ACLfile [/c] [/l] [/q]]

The first parameter in the syntax is always the command itself. In this case, it is the icacls command. This command is used to manage permissions from the Command Prompt.

When you see italicized parameters, these represent variables. For example, the parameter FileName should be replaced with an actual filename and the parameter Directory should be replaced with an actual directory of folder name, such as:

icacls file1.txt

The preceding command would display the current permissions on the file named file1.txt.

Parameters inside of square brackets are optional. For example, with the icacls command, you can use the /t switch if you need it, but it is not required for the command to process.

When you see […], this indicates that you can repeat the previous parameter as often as needed in the command. For example, when using the icacls command to grant permissions, you can do so for multiple SIDs (security IDs) at the same time.