Is there an equivalent of cd - for cp or mv?
If your shell has cd -
, then it will likely have either the special variable $OLDPWD
and/or the shortcut ~-
for the directory you've been in previously.
cp Makefile LICENSE "$OLDPWD/"
cp Makefile LICENSE ~-
cat ~-/Makefile
Indeed the POSIX shell language (upon which ksh/bash/zsh are built) specifies that cd -
should be equal to cd "$OLDPWD"
.
You can always use shell backquotes.
They act like a subshell : the command in the backquotes is executed first, and its output is placed as argument of the main command.
~/folderA$ cd ../folderB
~/folderB$ cp Makefile `cd -`
# gets expended to "cp Makefile ~/folderA"