TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The perils of file replacement on *nix

17 pointsby r11tabout 15 years ago

5 comments

jluxenbergabout 15 years ago
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 未加载
fexlabout 15 years ago
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 未加载
zapharabout 15 years ago
How many people actually use shell redirection to copy and filter a file?
评论 #1216846 未加载
评论 #1217065 未加载
tedunangstabout 15 years ago
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 未加载
nathanbabout 15 years ago
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 未加载