A request for cp flag

Matthew Seaman matthew at FreeBSD.org
Mon Oct 17 14:59:29 UTC 2016

On 2016/10/17 15:50, Manish Jain wrote:
> I am using FreeBSD 10.3 amd64 with bash as the login shell.
> I occasionally face a problem while copying contents with cp. The -R 
> flag of cp takes the source name as this : If the source_file ends in a 
> /, the contents of the directory are copied rather than the directory 
> itself.
> Now, I am pretty sure, there must be good reasons for cp to behave in 
> that manner by default. But it also creates significant opportunities 
> for things to go wrong the way shell completion of directory names works.
> Could it considered a valid request that an extra flag (perhaps -r) be 
> implemented that does the reverse : copy out src rather than src/* ?

You're not going to get anyone to change the behaviour of a core command
like cp(1) I'm afraid.  For all that you dislike the behaviour when
copying a directory path that ends in '/' there will be many, many more
people that have written scripts that depend on that exact behaviour and
will be exceedingly peeved if those scripts stop working.

However, as you say: you're using bash.  You can define a shell function
'cp' which is a wrapper around the original cp(1) and that strips any
trailing '/' characters from command arguments.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 972 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20161017/69abe27a/attachment.sig>

More information about the freebsd-questions mailing list