Score:0

Copying files from the terminal with confirmation message before copying each file

ao flag

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.

terdon avatar
cn flag
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?
Score:6
hr flag

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
sudodus avatar
jp flag
Thanks for 'find -ok command' :-)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.