在复制每个文件之前从带有确认消息的终端复制文件

0 command-line copy

我想将文件从一个文件夹复制到另一个文件夹,但我想让终端在复制每个文件之前要求确认复制文件。有什么办法吗?

我知道有,cp -i但只在覆盖之前询问。

ste*_*ver 6

你可以用find命令的-ok谓词来实现一些东西:

   -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.
Run Code Online (Sandbox Code Playgroud)

所以例如

$ 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
Run Code Online (Sandbox Code Playgroud)