UNIX tip of the day: pushd

Bildschirmfoto-2021-04-14-um-14.26.14

I am frequently surprised by the number of colleagues I have who do not know about the BASH builtins pushd and popd. I myself remember seeing them for the first time in a script about 10 years ago, and had to look up the commands. At first I didn’t quite understand the point, but now I use them all the time. It is a simple concept – instead of using cd to change directories, use pushd – this will do 2 things: 1) change the directory, and 2) push it onto a stack of all the different working directories you have used. This is really handy when you are in the middle of a task, and need to do something else quickly in a different directory. Once you are done, simply run popd and then you are back to where you started. You can the see the contents of your directory stack using dirs.

This can also be used very effectively in BASH scripts. Sometimes certain commands might expect to be run from a certain directory.

Join 165 other subscribers

archives

  • 2024 (10)
  • 2023 (8)
  • 2022 (15)
  • 2021 (19)
  • 2020 (1)
  • 2019 (1)
  • 2018 (2)
  • 2017 (1)
  • 2016 (2)
  • 2015 (5)
  • 2014 (5)
  • 2013 (2)
  • 2011 (7)
  • 2010 (10)
  • 2009 (50)
  • 2008 (28)
  • 2007 (31)
  • 2006 (8)

Category