如何回显文件中的文本并删除以前的内容?

How to echo text in a file and delete previous content?

我想删除文件中以前的内容,只显示新内容。

echo 'new contents' >file

这将在 echo 将字符串 new contents 插入其中之前截断(清空)名为 file 的文件(假设该文件可由当前用户写入且不可写入)一个目录)。