0

I want to copy files from one folder to another, but I want to make the terminal ask for confirmation of copying files before copying each file. Is there any way?

I know there is cp -i but that only asks before overwriting.

1
  • Can you explain the use case a bit? What's the point of asking for confirmation for every file? If you don't want to copy something, then don't copy it. In what context would a confirmation be useful?
    – terdon
    Aug 14, 2021 at 13:04

1 Answer 1

5

You could implement something with the find command's -ok predicate:

   -ok command ;
          Like  -exec but ask the user first.  If the user agrees, run the
          command.  Otherwise just return false.  If the command  is  run,
          its standard input is redirected from /dev/null.

So for example

$ find . -maxdepth 1 -mindepth 1 -name '*.jpg' -ok cp -t ../newdir {} \;
< cp ... ./aaa.jpg > ? y
< cp ... ./aaa-small.jpg > ? n
< cp ... ./bbb.jpg > ? n
< cp ... ./ccc-small.jpg > ? y
< cp ... ./ccc.jpg > ? y
< cp ... ./bbb-small.jpg > ? n

$ ls ../newdir
aaa.jpg  ccc.jpg  ccc-small.jpg
1
  • Thanks for 'find -ok command' :-)
    – sudodus
    Aug 14, 2021 at 8:59

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.