0

I would like cp to prompt before overwriting so I am using -i.

(I might sometimes use an alias for cp, or similar, so cp always occurs with -i).

I may want to say overwrite all. I know that's the default but since i'm using -i I don't see that.

I want to easily be able to make it do 'yes' to all, or 'no' to all.

I am not asking how to bypass an alias, I want the -i.

Here is my attempt at forcing yes, given -i.

~$ mkdir test1
~$ cd test1
~/test1$ mkdir smalls
~/test1$ touch a.a
~/test1$ touch b.b
~/test1$ cp -i ?.? smalls
~/test1$ cp -i ?.? smalls
overwrite smalls/a.a? (y/n [n]) y
overwrite smalls/b.b? (y/n [n]) y
~/test1$ yes|cp -i ?.? smalls
overwrite smalls/a.a? (y/n [n]) overwrite smalls/b.b? (y/n [n]) ~/test1$ 
~/test1$ 
~/test1$ yes ''|cp -i ?.? smalls
overwrite smalls/a.a? (y/n [n]) not overwritten
overwrite smalls/b.b? (y/n [n]) not overwritten
~/test1$ 

So I manage to force 'y' to all but then I don't get new lines.

When I try yes ''| then it doesn't send a yes.

I'd also like to be able to pass an 'n'/'no' too.

And I may have many files so i'm not looking to manually type 'y' or 'n' for each file.

I don't mind a solution that doesn't involve the 'yes' command.

1
  • What is wrong with your yes|cp -i …? No newlines? Normally the newlines are echoed back by your terminal when you type y<Enter>, y is echoed first in the same way. Here y\n come from yes, the terminal is not involved. You can emulate interactive usage with expect, but spawning cp in expect makes no sense in this context because it won't be the alias in the first place. Not using the alias is a good way; yes | cp … is a good way. You rejected both and I don't really see the point of the question (maybe except the "no" part, a solution may be yes n or cp -n of GNU cp). Dec 7, 2021 at 11:03

2 Answers 2

0

You can use 'yes |' in front of your code.

yes | cp -i ?.? smalls
-1

Plenty of ways to bypass the alias to use native cp:

  • Use the command builtin: command cp
  • Use the full path of the command: /bin/cp
  • Add a \ anywhere in the command name, for example: \cp
  • Quote the command: "cp" or 'cp'
5
  • -1 why on earth are you telling me how to bypass an alias, I very clearly never asked such a thing at all
    – barlop
    May 24, 2019 at 21:40
  • I have now added this line I am not asking how to bypass an alias, I want the -i. making it even more clear and obvious.
    – barlop
    May 24, 2019 at 21:42
  • And if I wanted to ask how to bypass an alias, i'd have asked that, without any of the other stuff, but I didn't.
    – barlop
    May 24, 2019 at 21:43
  • Sorry, I thought you wanted a practical solution.
    – xenoid
    May 24, 2019 at 22:46
  • a solution to the question I asked, whose first line includes the words "I am using -i."
    – barlop
    May 24, 2019 at 22:48

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.