Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As in, say I execute pwd to return the current directory and want to dump this in a script file so that I can come back, but I then need to prefix it with 'cd '?

share|improve this question
up vote 4 down vote accepted

I don't quite understand what you are asking here.

Maybe you could try something like this?

echo cd `pwd` > /tmp/file
share|improve this answer
I was messing around with awk & pipes. Doh. Thanks so much! – M. Tibbits Aug 20 '11 at 2:02

In case you're trying to accomplish this:

cd -
# Changes directory to the last one you were in


pushd and popd
# Push current directories on a stack with pushd
# Pop them back out (change to them) with popd
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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