TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The perils of file replacement on *nix

17 点作者 r11t大约 15 年前

5 条评论

jluxenberg大约 15 年前
sponge (1) is a simple way to do this, but not available on all systems. See <a href="http://joey.kitenet.net/code/moreutils/" rel="nofollow">http://joey.kitenet.net/code/moreutils/</a>
评论 #1217218 未加载
评论 #1303673 未加载
fexl大约 15 年前
I use this technique a lot:<p><pre><code> mv thing thing.old &#38;&#38; mv thing.new thing </code></pre> It works whether the thing is a file or a directory; I have an automatic backup called thing.old; I suppose it's reasonably atomic; and I can do it in ssh with no worries about losing the network connection in between the two moves.
评论 #1217252 未加载
zaphar大约 15 年前
How many people actually use shell redirection to copy and filter a file?
评论 #1216846 未加载
评论 #1217065 未加载
tedunangst大约 15 年前
Diagnosis for 2 is wrong. The shell won't be scheduled to truncate the file after the shell is scheduled to fork/exec cat. The shell is not multithreaded.
评论 #1217266 未加载
nathanb大约 15 年前
I don't understand this article. Saying "Replacing the contents of a file on the UNIX command line using the standard cp/mv commands is surprisingly tricky" is like saying "driving a car using only your ass is surprisingly tricky". That's true, but when there are standard, simple, non-tricky ways to do it then you're really just limiting yourself.<p>But hey, I'll play along. Won't this work: cp file /dev/stdout &#62; file
评论 #1217005 未加载