shell – echo >> style appending,但是文件的开头

前端之家收集整理的这篇文章主要介绍了shell – echo >> style appending,但是文件的开头前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在UNIX shell中有什么好的技巧可以将行追加到文件的开头吗?例如.类似于
echo "Foobar" >> file.txt

…但是新线路会先于现有线路吗?

分两步:
content=$(cat file.txt) # no cat abuse this time
echo -en "foobar\n$content" >file.txt

猜你在找的Bash相关文章