myd
2021-08-11 09:52:08 +08:00
刚刚试了一下,在文件开头插入一样确实很慢,但在文件结尾追加很快:
```
[root@VM-0-8-centos file_test]# ls -lh
total 4.8G
-rw-r--r-- 1 root root 4.8G Aug 11 09:39 big.txt
[root@VM-0-8-centos file_test]# head -n 2 big.txt
Hello World !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hello World !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[root@VM-0-8-centos file_test]# time sed -i '1 i\add first line' big.txt
real 2m12.840s
user 0m32.787s
sys 1m39.221s
[root@VM-0-8-centos file_test]# head -n 2 big.txt
add first line
Hello World !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
```
建议:实际存储时把文件切割,比如 20M 一个。读取的时候再拼接。