Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

linux - 如何在没有确认的情况下强制cp覆盖(How to force cp to overwrite without confirmation)

I'm trying to use the cp command and force an overwrite.

(我正在尝试使用cp命令并强制覆盖。)

I have tried cp -rf /foo/* /bar , but I am still prompted to confirm each overwrite.

(我试过cp -rf /foo/* /bar ,但仍然提示我确认每次覆盖。)

  ask by thiyagu114 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do yes | cp -rf xxx yyy

(你可以做yes | cp -rf xxx yyy)

yes | cp -rf xxx yyy , but my gutfeeling says that if you do it as root - your .bashrc or .profile has an alias of cp to cp -i , most modern systems (primarily RH-derivatives) do that to root profiles.

(yes | cp -rf xxx yyy ,但我的gutfeeling说,如果你以root身份执行 - 你的.bashrc.profile的别名是cpcp -i ,大多数现代系统(主要是RH衍生系统)都是根配置文件。)

You can check existing aliases by running alias at the command prompt, or which cp to check aliases only for cp .

(您可以通过在命令提示符下运行alias来检查现有别名,或者which cp来检查仅为cp别名。)

If you do have an alias defined, running unalias cp will abolish that for the current session, otherwise you can just remove it from your shell profile.

(如果您确实定义了别名,则运行unalias cp将取消当前会话的unalias cp ,否则您只需将其从shell配置文件中删除即可。)

You can temporarily bypass an alias and use the non-aliased version of a command by prefixing it with \ , eg \cp whatever

(您可以暂时绕过别名并使用命名的非别名版本,前缀为\ ,例如\cp whatever)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...