简体   繁体   English

什么是用bash中的符号链接替换文件的DRYest方法

[英]What's the DRYest way to replace a file with a symlink in bash

I have an existing file which I'm replacing with a symlink to another file. 我有一个现有的文件,我用一个符号链接替换另一个文件。 So I basically need to do this: 所以我基本上需要这样做:

rm orig
ln -s /var/better orig

I DRYed the above to this: 我把上面的内容干掉了:

{rm,ln\ -s\ /var/better}\ orig\;

But it no longer works. 但它不再有效。 The shell now complains: shell现在抱怨:

-bash: rm orig;: command not found

Is there a way to make the DRY form work? 有没有办法让DRY表格有效?

You can just use "-f". 你可以使用“-f”。

ln -sf /var/better orig

From man ln 来自man ln

-f, --force remove existing destination files -f, - force删除现有目标文件

你需要的只是cp:

cp -sf /var/better orig

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 bash 中,复制文件的最佳方法是什么,如果它是符号链接,还要复制链接到的文件? - in bash what is the best way to copy a file, and if it is a symlink also copy the linked-to file? 在 Bash 中用另一个文件内容替换文件内容的最有效(就速度和行数而言)方法是什么? - What is the most efficient (in terms of speed and number of lines) way to replace a file content by another file content in Bash? bash:检查文件或符号链接(甚至悬空)是否存在? - bash: check if file or symlink (even dangling) exists? 有没有一种方法可以创建指向目录的* contents *的符号链接? - Is there a way to create symlink[s] to directory's *contents*? 在MacOS上解决bash上拆分工具的文件限制(676个文件)的最简单方法是什么 - What's the easiest way to get around the split utility's file limit (676 files) on bash in MacOS 在bash中交换文件中2个单词的最佳方法是什么 - what is the best way to interchange 2 words in a file in bash 什么是在bash中修改文件的优雅方式 - What is an elegant way to modify file in bash 如何在 Bash 中测试文件或符号链接的存在,甚至是损坏的文件或符号链接? - How to test existence of a file or symlink, even broken one, in Bash? 这个bash代码替换文件中的单词有什么问题? - What's wrong with this bash code to replace words in files? 使用bash,awk或sed对文件中的每个数字进行位移位和位掩码的最快方法是什么? - What's the quickest way to bit shift and bit mask every number in a file using bash, awk or sed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM