Interactively, there's an
icp command like
imv, that gives you a readline editing environment with the filename. It's in the "renameutils" package. See the man page
...$ icp ~/foo/bar/baz
> /home/user/foo/bar/baz # edit this and hit return. it runs cp for you
Tab completion is available while editing, at least if the path doesn't contain spaces. It seems to fail with those, unfortunately.
They prompt before overwriting the destination file if it exists.
imv have some default options they pass to
mv respectively, including
--no-preserve (of attributes like timestamps).
Or, line-editing features make it very easy and fast to duplicate the path without typing it again.
Start by typing
cp ~/mydir/subdir/ (tab completion is available)
If the path contains no spaces, a single ctrl-w will "kill" it, storing it in the kill ring. If there are spaces, it'll take more than 1, and if you overshoot and kill the
cp as well, it'll be part of the kill-ring entry even if you use ctrl-/ to undo the overshoot.
Or ctrl-a, ctrl-right-arrow to place the cursor after the
cp, then ctrl-k to kill-to-end-of-line.
Yank back what you killed with ctrl-y, so your command line is back to step 1, but with the directory ready to paste
type the source filename (tab completion is available)
Hit space, then yank another copy of the path with ctrl-y. Now your command line looks like
cp ~/mydir/subdir/file1 ~/mydir/subdir/
Type the final filename (tab completion is available)
The same building blocks can be used in other orders. For example if you started typing or copy/pasting the source path including filename, and only after that you realize you want the copy to be in that directory, ctrl-left-arrow to move the cursor backward-word before killing/yanking the directory part, then ctrl-e for end of line before yanking another copy of it.
Or if you want to give the copy a similar filename, kill / 2x yank the whole path including filename, then edit the 2nd copy (destination). Again, tab-completion is available at all stages.
If you accidentally kill something else so ctrl-y yanks the wrong thing, alt-y to cycle back through previous kill-ring entries.
These interactive line-editing tools are extremely useful all the time, not just for
cp. Cursor-movement by "word", and kill forward/backward word, are highly useful for quickly editing and copying paths.