popd - macOS


popd is a macOS shell command that allows you to quickly navigate back to the directory you were previously in. This is helpful if you have navigated to multiple directories and want to return to a specific one without having to manually navigate back through each one.


popd [directory]
  • directory: (Optional) The directory you wish to return to. If not specified, the shell will pop the last directory from the directory stack.


There are no options or flags available for the popd command.


  • Return to the previous directory:
  • Return to a specific directory:
popd /Users/johndoe/Documents

Common Issues

  • Directory does not exist: If the specified directory does not exist, popd will return an error message.
  • No previous directory: If there is no previous directory to return to, popd will return an error message.


popd can be used with other macOS commands to automate tasks. For example, the following command combines popd with ls to list the files in the previous directory:

popd; ls
  • cd: Change the current working directory.
  • pushd: Push the current working directory onto the directory stack.