How to append output to the end of a text file

2019-01-02 22:14发布

How do I append the output of a command to the end of a text file?

标签: bash shell
8条回答
对你真心纯属浪费
2楼-- · 2019-01-02 23:12

Use the >> operator to append text to a file.

查看更多
走好不送
3楼-- · 2019-01-02 23:15

for the whole question:

cmd >> o.txt && [[ $(wc -l <o.txt) -eq 720 ]] && mv o.txt $(date +%F).o.txt

this will append 720 lines (30*24) into o.txt and after will rename the file based on the current date.

Run the above with the cron every hour, or

while :
do
    cmd >> o.txt && [[ $(wc -l <o.txt) -eq 720 ]] && mv o.txt $(date +%F).o.txt
    sleep 3600
done
查看更多
登录 后发表回答