5
1
The command
cd -
will change the pwd to the last directory.
Is there a way to know which directory it is, so that I'll know where I am CD'ing to?
5
1
The command
cd -
will change the pwd to the last directory.
Is there a way to know which directory it is, so that I'll know where I am CD'ing to?
15
Yes, it is $OLDPWD.
~$ cd src/
~/src$ cd ..
~$ echo $OLDPWD
/home/$USER/src
5
The previous directory is saved in $OLDPWD
2
You can also use ~- (anywhere you can use tilde expansion) instead of $OLDPWD:
# Copy a file from the previous working directory.
cp ~-/file1 .
There is also ~+ for $PWD, which is useful for commands which require an absolute directory:
./configure --prefix ~+/root
Note that things like --prefix=~+/root
won't work due to the rules of tilde expansion; use --prefix="$PWD/root"
instead.
1"echo ~-" will output the same information – njd – 2010-02-19T15:23:15.940
Always a pleasure :) – None – 2009-12-18T13:18:54.157