简体   繁体   English

用另一个文件的内容替换文件的所有内容

[英]Replace all content of file with the content of another file

Is there a way to replace all content of a file with the content of another file without destroying the first file? 有没有办法在不破坏第一个文件的情况下用另一个文件的内容替换文件的所有内容?

If I have a file in the current directory called myfile.txt , if I do the following: 如果当前目录中有一个名为myfile.txt的文件,请执行以下操作:

cp updatedfiles/myfile.txt myfile.txt

then my old file is deleted and replaced with a new file (with the same name). 然后我的旧文件将被删除并替换为新文件(具有相同的名称)。 I do not want to delete the existing file, I just want to change the content of the file. 我不想删除现有文件,我只想更改文件的内容。 How to do this? 这个怎么做?

cat updatedfiles/myfile.txt > myfile.txt

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM