If I saw that situation coming as a one-off, I might:
a=`pwd`
cd /somewhere/else
cp "$a/myfile" .
If there were directories that I found myself copying files out of semi-regularly, I would probably define some mnemonic variables for them in my .profile.
Edited to add:
After sleeping on it, I wondered how closely I could get to other GUI / OS behaviors where you select some number of files, "cut" or "copy" them, then "paste" them somewhere else. The best selection mechanism I could come up with was your brain/preferences plus the shell's globbing feature. I'm not very creative with naming, but this is the basic idea (in Bash syntax):
function copyfiles {
_copypastefiles=("$@")
_copypastesrc="$PWD"
_copypastemode=copy
}
function cutfiles {
_copypastefiles=("$@")
_copypastesrc="$PWD"
_copypastemode=cut
}
function pastefiles {
for f in "${_copypastefiles[@]}"
do
cp "${_copypastesrc}/$f" .
if [[ ${_copypastemode} = "cut" ]]
then
rm "${_copypastesrc}/$f"
fi
done
}
To use it, put the code into ~/.bash_profile, then cd
to the source directory and run either copyfiles glob*here
or cutfiles glob*here
. All that happens is that your shell expands the globs and puts those filenames into an array. You then cd
to the destination directory and run pastefiles
, which executes a cp
command for each source file. If you had previously "cut" the files, then pastefiles also removes the source file (or, tries to). This doesn't do any error-checking (of existing files, before potentially clobbering them with the cp
; or that you have permissions to remove the files during a "cut", or that you can re-access the source directory after you move out of it).
cd
command, so you can justcd -
to go back to the previous directory, up-arrow to recall thecd
command, and edit the line to becp
instead ofcd
. (ctrl-a(beginning-of-line), alt-d (kill-word),cp -a
, ctrl-e(end-of-line)).M-x term
you can use Emacs' clipboard.