pushd popd – top 5 tips

  • pushd dirA ###  1) push current dir, 2) push dirA, 3) Enter (i.e. cd into) dir1 i.e. the new top
  • popd ### without arg — means 1) pop 2) Enter the new top in the stack. I guess the item “removed” is forgotten completely.
  • pushd ### without arg — means 1) swap top two on the stack. 2) “Enter” (i.e. cd into) new top
 –Gory details
### I feel top item is always, always kept in sync with current dir. An understanding of the stack is essential. The stack is shared by cd, pushd, popd.
  • cd – ### a single dash — means “Enter” previous directory (in history, not the stack). Overwrite top.
  • pushd +2 ### means 1) identify the 3rd (not 2nd) on the stack. Rotate it to top. 2) Enter new top
  • cd dir1 # replace top item on the stack with dir1
  • dirs -v # print stack. Readonly operation.
  • popd +2 # identify the 3rd (not 2nd) on the stack and remove it. Don’t change current directory, since top is unaffected.
  • popd +0 # Probably pop the top. Enter the new top.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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