shell script 紀錄10行資料 - Linux

Table of Contents

Q:

把目前的日期時間(時分秒)寫入第一行,其他資料往下移一行

,全部資料只能保存10行,超過10行資料一律刪除。


時分秒的已經寫好了,但是不知道怎麼寫超過10行把最先記錄的資料刪除。

有人可以提供網站或是解答嗎?

感謝...

--

All Comments

Carol avatarCarol2011-11-30
使用 tail -n
Mia avatarMia2011-12-01
這樣就會顯示最新的10筆資料嗎?
George avatarGeorge2011-12-03
tail -n 10
Caroline avatarCaroline2011-12-04
date >> file; tac file | head -n 10 - > file;
新手不負責任發言,還沒測試過。
Aaliyah avatarAaliyah2011-12-07
抱歉,最前面還要加上tac file > file;
George avatarGeorge2011-12-11
其實只要echo -e $(date)"\n"$(head -n 9 file) > file;