Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
watch clears the screen and runs a command every 2 seconds (or the interval you choose). It is the quick way to follow a rollout, a disk that fills up, or a queue that empties, without writing a loop.
With -d it marks what changed since the last run. Put the command in quotes when it has pipes.
Zo schrijf je het
watch [OPTIONS] COMMANDOpties 10
Meest gebruikt
Options
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Follow the pods during a rollout
watch -n 1 kubectl get pods -o wide2Mark what changes
watch -d 'kubectl get deploy shop'3A disk that fills up
watch -n 5 'df -h / /var'4Count open connections to port 443
watch "ss -Htn state established '( sport = :443 )' | wc -l"5Stop as soon as something changes
watch -g 'kubectl get pod migrate-db -o jsonpath={.status.phase}' && echo "phase changed"6Wait until a file appears
watch -g ls /var/run/app.ready7Keep the colours of the command
watch -c 'git -c color.status=always status -s'8A queue in RabbitMQ
watch -n 2 'rabbitmqctl list_queues name messages'9Memory every second, without the header
watch -t -n 1 free -m10Stop when the health check fails
watch -e -n 10 'curl -fsS http://localhost:8080/health'11Docker containers and their state
watch 'docker ps --format "table {{.Names}}\t{{.Status}}"'
Niets past bij dit filter.
Let op
- Quote the whole command when it has
|,>or;, or the pipe applies to watch itself. - Short intervals with heavy commands (big kubectl lists) add load to the API server.
Tips om te onthouden
kubectl get pods -wstreams changes without watch; watch is better for a full table view.- Ctrl+C stops watch.
Exitcodes
0 | Normal exit. |
1 | Bad options. |
2 | Fork failed. |
8 | -e and the command failed. |