需求:向 file.txt 添加內容 "hello world"
方法1:文本編輯器
[root@linux test_shell]# vim file.txt
方法2:輸出重定向
[root@linux test_shell]# echo "hello world" >> file.txt
[root@linux test_shell]# cat >> file.txt hello world [root@linux test_shell]#
備注:按 Ctrl + D 結束編輯。
方法3:輸入輸出重定向
[root@linux test_shell]# cat >> file.txt << end > hello world > end [root@linux test_shell]#
方法4:sed流編輯器
[root@linux test_shell]# sed -i '$a hello world' file.txt
總結:
添加內容較少時,推薦使用 方法2
添加內容較多時,推薦使用 方法3
在指定位置 添加/插入/修改 內容時,使用 方法4