Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 37
    Thanks, I totally understand the concept of stack and how this commands work. However, I'm looking for some practical reasons for keeping stack with directories (when you have tab completion, cd -, aliases for shortening cd .., etc.). Commented May 25, 2013 at 18:26
  • 39
    I often use pushd & popd in scripts b/c they save me from having to remember where I was coming from, I can always just popd to get back from where I came. I usually do popd >/dev/null 2>&1 to make it silent. I use cd- everyday in my shell. There are some other time saving tips in this article as well: thegeekstuff.com/2008/10/…. Commented May 25, 2013 at 18:31
  • 2
    @Garrett - none that I can conceive. Commented Aug 22, 2014 at 1:11
  • 9
    @Garrett @slm since cd - only tracks the last directory, i imagine it would be possible to have issues if you call a function which also changes directory internally. in that case, the function would end up resetting - to your current directory, not the directory you want to pop back to. pushd/popd is the safest method. Note: i haven't tested my theory. Commented Nov 10, 2014 at 20:52
  • 6
    Why not going back to ~/somedir/dir3 after the first popd? Commented Feb 18, 2016 at 22:03