如何复制或移动文件而不被要求覆盖?

use*_*951 12 shell alias cp

我试过的:

root@host [/home1]# cp -f hello /home3
cp: omitting directory `hello'
root@host [/home1]# cp -rf hello /home3
cp: overwrite `/home3/hello/.buildpath'? y
cp: overwrite `/home3/hello/.bash_logout'? y
cp: overwrite `/home3/hello/.project'? ^C
Run Code Online (Sandbox Code Playgroud)

他们总是问我是否要覆盖。使用 mv 也不起作用。所以我该怎么做?

我尝试过的其他事情:

root@host [/home1]# cp -rf hello /home3
cp: overwrite `/home3/hello/.buildpath'? y
cp: overwrite `/home3/hello/.bash_logout'? y
cp: overwrite `/home3/hello/.project'? ^C
root@host [/home1]# cp -force hello /home3
cp: invalid option -- 'o'
Try `cp --help' for more information.
root@host [/home1]# cp --remove-destination hello /home4
cp: omitting directory `hello'
root@host [/home1]# cp --remove-destination hello /home3
cp: omitting directory `hello'
root@host [/home1]# cp --remove-destination -r hello /home3
cp: overwrite `/home3/hello/.buildpath'? ^C
root@host [/home1]#
Run Code Online (Sandbox Code Playgroud)

Chr*_*own 14

cp似乎是引起问题的东西的别名,或者它是一个函数。您可以删除别名/函数:

unalias cp
unset -f cp
Run Code Online (Sandbox Code Playgroud)

如果您现在只想覆盖它,您可以使用该command命令覆盖任何别名/函数定义:

command cp [...]
Run Code Online (Sandbox Code Playgroud)

如果您希望完全删除它,您可能需要查看 bash 启动文件。

  • `\cp` 也将避免别名。 (4认同)

sin*_*anu 14

要强制覆盖而不询问您应该使用命令mv和选项“-f”,使用 man 查看选项。

男人MV:

   -f, --force
          do not prompt before overwriting
Run Code Online (Sandbox Code Playgroud)

例子:

mv -f test.tmp test.txt
Run Code Online (Sandbox Code Playgroud)


小智 0

只需执行alias cp=cp,它将覆盖目标,而无需在此会话中询问。如果您想将其存储为标准行为,请将其存储在您的~/.bashrc.