1. 程式人生 > >Cat命令結合重定向功能實現文字內容寫入

Cat命令結合重定向功能實現文字內容寫入

Cat命令結合重定向功能實現文字內容寫入

將stdin標準輸入的內容重定向到test檔案(以覆蓋檔案內容的方式,若此檔案不存在,則建立之),且當stdin中含有EOF時完成寫入:

[root@localhost ~]# cat > test << EOF
> this is first line 
> this is second line
> this is thrid line
> this is fourth line
> EOF
[root@localhost ~]# cat test
this is first line 
this is second line
this is thrid line
this is fourth line

將stdin的內容追加到已存在的test檔案,且當stdin中含有EOF時完成寫入:

[root@localhost ~]# cat >> test << EOF
> this is five line
> this is sixth line
> EOF
[root@localhost ~]# cat test
this is first line 
this is second line
this is thrid line
this is fourth line
this is five line
this is sixth line

說明:以上的EOF可以替換為你想要的其它字串。