Push-Location VS Set-Location

Push-Location VS Set-Location

With both cmdlet you can set the current working folder in your console.

However, Push-Location becomes really interesting when you associate its use with Pop-Location. Both cmdlets act merely like the Back and Forward buttons from the Windows File Explorer.

Windows File Explorer Back Forward

With Push-Location and Pop-Location, the history is named the stack.

However, unlike with the Windows File Explorer, with Pop-Location you cannot pick-up one location in the midst of the stack. The Push/Pop system works with the LIFO method:

  • Every time you push another location, the former one is added to the top of the stack.
  • Every time you pop a location, it is removed from the top of the stack.

As you can notice in the following example and screenshot:

  • The C:\Windows\System32\LogFiles location has not been added to the stack because no other location has been pushed after it.
  • The C:\Windows location was the latest to be added to the stack and also the first one to be popped out and remove from the stack.

LIFO Push-Location Pop-Location

Interestingly Push-Location and Pop-Location can handle multiple stacks.

As you can see in the following example, I filled 2 stacks and then I popped the latest location from one of both stacks.

In the next example and screenshot, you can notice that:

  • I created and filed a stack named Windir and then I created an filed another stack named Programs.
  • I popped the latest location from the first stack named Windir

Push-Location Pop-Location multiple stacks

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s