The tail -f, –follow[={name|descriptor}] option outputs appended data as the file grows. The -F option is the same as tail –follow=name with –retry option.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
## create a script to insert 1 item every 2 second ## and rename the file after some changes cat <<'EOF'> myscript.sh #!/bin/bash i=1; k=1 > myfile1 while [ $i -le 29 ] do echo "$i" >> myfile$k j=$(($i%10)) l=$(($i%15)) if [ $j -eq 0 ]; then mv myfile1 myfile2; k=2; fi if [ $l -eq 0 ]; then mv myfile2 myfile1; k=1; fi sleep 2 ((i++)) done EOF ## execute the script in background chmod +x myscript.sh ./myscript.sh & ## default tail myfile ## returns the last 10 lines and exit ## tail -f or --follow[={name|descriptor}] or -F option tail --follow=descriptor myfile1 ## displays last 10 lines but does not exit ## new data are appended in in output ## stops at 10, does not reopen the file ## press control + c to exit ./myscript.sh & tail --follow=name myfile1 ## displays last 10 lines but does not exit ## new data are appended in in output ## stops at 20, reopens the file priodically ## press control + c to exit ./myscript.sh & tail -F myfile1 ## same as --follow=name --retry ## displays last 10 lines but does not exit ## new data are appended in in output ## stops at 20, reopens the file priodically ## press control + c to exit rm my* |