简体   繁体   中英

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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