I'm trying to send disk space update to multiple files so that one file will have current update which will get overwritten every hours and another file can have all the updates where it appends the output everytime it runs. but its adding output only on the file where it appends but not in the first file(/tmp/daily..)

code italic

filename=$(date +"%d_$m-%H:%M")
df -kh  > /tmp/daily"$filename".txt >> /tmp/grand.txt

Is there anyway I can have these where first file(/tmp/daily...) will be overwritten with latest output and second file (/tmp/grand.txt) will append whenever it executes?


1 Answer 1

df -kh | tee -a /tmp/grand.txt > /tmp/daily"$filename".txt

To output the same data to more than one place, you must duplicate that data. This is what tee does.

In the pipeline above, tee gets the output of df. It then appends it to the grand.txt file and also passes a copy of the data to its standard output stream. That output stream is redirected to the daily file with a truncating output redirection.


df -kh | tee /tmp/daily"$filename".txt >> /tmp/grand.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .