4

I'm on a Mac and the cp and mv commands are killing me due to them copying the contents of a directory if a trailing slash is present. It has bitten me more than once when I use tab completion to specify the directory I want to copy.

I have noticed zsh has a neat feature that removes the trailing slash if it's not needed after a space or enter key is pressed. Is there any way to have bash mimic this behavior?

4

Put

set mark-directories off

in your ~/.inputrc, and ensure you have export INPUTRC=~/.inputrc in ~/.bashrc.

If you want to set this immediately then you can use bash's bind command:

bind 'set mark-directories off'

See also How to avoid cp -r ~/some/folder/ . copying all files to the current folder's top level?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.