In Mac OS Terminal, is there a way to either have the Terminal remember the directory it was on after I last quit the Terminal application or easily "cd" to a recent directory?

I often "cd" every time I start Terminal to only a couple of directories which have spaces in them, and I am looking for an easier way to do this than either typing the whole path and escaping the spaces or finding the right folder in Finder, typing "cd" and dragging the folder from Finder into Terminal.

  • tab completion? – Spiff Jan 17 '18 at 22:14
  • @Spiff I tried tab completion, but what I did just showed me all available directories in the current directory one by one, so that didn't save any time to get me straight to the recent directory – Mike Eng Jan 17 '18 at 22:28

If you type cd and then start to type a path and hit
, it should auto-complete the name of the file or folder you were typing, if you typed enough for it to be non-ambiguous. So you can often enter paths very quickly by just typing the first couple letters of the next directory in the path and hitting tab.

Another approach, if it really is the same few folders every time and they don't change often, is you could add alias commands to the appropriate shell startup script to make it easy:

alias cda="cd /Path/to/Silly\ Directory\ with\ Spaces\ A"
alias cdb="cd /Path/to/Silly\ Directory\ with\ Spaces\ B"
alias cdc="cd /Path/to/Silly\ Directory\ with\ Spaces\ C"

…this example would allow you to type cda and it will automatically execute:

cd /Path/to/Silly\ Directory\ with\ Spaces\ A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.