foxfirefey: A fox colored like flame over an ornately framed globe (Default)
foxfirefey ([personal profile] foxfirefey) wrote in [community profile] command_liners2009-06-25 11:51 am
Entry tags:

Going to your previous current working directory

I learned this one recently from a coworker:

cd -


This will allow you to switch to your previous current working directory. So:

# Go into first directory
cd ~/path/to/first/dir
# Go into second directory
cd ~/path/to/second/dir
# This takes us back to the first directory
cd -
# This takes us back to the second directory
cd -


This is really useful if you have two main directories you're currently working in.
marnanel: (Default)

[personal profile] marnanel 2009-06-28 10:18 pm (UTC)(link)
I didn't know about that. Thank you!

Another way of switching between two directories is to use "pushd" with no arguments, which switches the top two directories in the "dirs" stack. So:

cd ~/fred
pushd ~/barney
(now in ~/barney)
pushd
(now in ~/fred)
pushd
(now in ~/barney)