180 lines
6.9 KiB
HTML
180 lines
6.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
|
|
<meta http-equiv="X-Content-Type-Options" content="nosniff">
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
<link rel="icon" type="image/x-icon" href="../favicon.ico">
|
|
<script>
|
|
// Apply theme immediately to prevent flash
|
|
(function() {
|
|
const theme = localStorage.getItem('theme') ||
|
|
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
})();
|
|
</script>
|
|
<title>watch Cheatsheet - Cheatsheets - Launch Pad</title>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
|
|
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
|
|
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
|
|
</button>
|
|
<br/><br/>
|
|
<div class="name">
|
|
__ _______________________ _________._________________________
|
|
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
|
|
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
|
|
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
|
|
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
|
|
\/ \/ \/ \/ \/ \/ \/
|
|
</div>
|
|
<div class="blog-page-header">
|
|
<div class="blog-header-content">
|
|
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
|
|
</a>
|
|
<h1 class="blog-page-title">watch Cheatsheet</h1>
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-container">
|
|
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="blog-post">
|
|
<div class="blog-post-content">
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
<hr>
|
|
<p>watch executes a command repeatedly and displays the output fullscreen. Useful for monitoring system resources, processes, logs, and other changing data in real-time.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>watch <command> - Execute command every 2 seconds</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -n <interval> <command> - Set update interval in seconds</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -d <command> - Highlight differences between updates</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -t <command> - No title bar</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -b <command> - Beep on command exit</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -e <command> - Exit on error</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Display Options</h2>
|
|
<ul>
|
|
<li>watch -n <seconds> <command> - Update interval</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -d <command> - Highlight differences</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -d=cumulative <command> - Cumulative highlighting</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -t <command> - Turn off header</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -g <command> - Exit when output changes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -c <command> - Interpret ANSI color codes</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Behavior Options</h2>
|
|
<ul>
|
|
<li>watch -b <command> - Beep if command has non-zero exit</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -e <command> - Exit on error</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -p <command> - Precise timing (attempts to run at exact intervals)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>watch -x <command> - Execute command with execvp()</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Basic Monitoring</h3>
|
|
<pre><code>watch date</code></pre>
|
|
<p>Watch date update every 2 seconds.</p>
|
|
<h3>Custom Interval</h3>
|
|
<pre><code>watch -n 1 date</code></pre>
|
|
<p>Update every 1 second.</p>
|
|
<h3>Highlight Differences</h3>
|
|
<pre><code>watch -d ls -l</code></pre>
|
|
<p>Highlight changes in directory listing.</p>
|
|
<h3>Monitor Processes</h3>
|
|
<pre><code>watch -n 1 'ps aux | grep process'</code></pre>
|
|
<p>Monitor specific processes.</p>
|
|
<h3>Monitor Disk Usage</h3>
|
|
<pre><code>watch -n 5 df -h</code></pre>
|
|
<p>Monitor disk usage every 5 seconds.</p>
|
|
<h3>Monitor Network</h3>
|
|
<pre><code>watch -n 1 'netstat -tuln'</code></pre>
|
|
<p>Monitor network connections.</p>
|
|
<h3>Monitor System Load</h3>
|
|
<pre><code>watch -n 1 uptime</code></pre>
|
|
<p>Monitor system load average.</p>
|
|
<h3>Monitor Memory</h3>
|
|
<pre><code>watch -n 1 free -h</code></pre>
|
|
<p>Monitor memory usage.</p>
|
|
<h3>Monitor Temperatures</h3>
|
|
<pre><code>watch -n 1 sensors</code></pre>
|
|
<p>Monitor hardware temperatures in real-time.</p>
|
|
<h3>No Title Bar</h3>
|
|
<pre><code>watch -t date</code></pre>
|
|
<p>Display without header.</p>
|
|
<h3>Exit on Change</h3>
|
|
<pre><code>watch -g 'ls file.txt'</code></pre>
|
|
<p>Exit when file appears.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Use -n to set custom update intervals (can use decimals like 0.5)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -d to highlight what changes between updates</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -t to remove the header for cleaner output</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -g to exit when output changes (useful in scripts)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use quotes for complex commands: watch -n 1 'command with args'</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Combine with sensors to monitor temperatures: watch -n 1 sensors</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -c to preserve ANSI colors in output</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -p for precise timing when exact intervals matter</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Press Ctrl+C to exit watch</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Great for monitoring logs, processes, and system resources</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|