152 lines
5.6 KiB
HTML
152 lines
5.6 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>cat 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">cat 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>cat (concatenate) displays file contents to stdout. One of the most fundamental Unix commands for reading files, combining files, and creating files.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>cat file.txt - Display file contents</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cat file1.txt file2.txt - Concatenate multiple files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cat file.txt | less - Pipe to pager</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cat > newfile.txt - Create file (Ctrl+D to finish)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cat >> file.txt - Append to file</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Options</h2>
|
|
<ul>
|
|
<li>-n - Number all output lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-b - Number non-blank lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-s - Squeeze blank lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-E - Show end of line with $</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-T - Show tabs as ^I</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-v - Show non-printing characters</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-A - Equivalent to -vET</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Display File</h3>
|
|
<pre><code>cat file.txt</code></pre>
|
|
<p>Show file contents.</p>
|
|
<h3>Number Lines</h3>
|
|
<pre><code>cat -n file.txt</code></pre>
|
|
<p>Display with line numbers.</p>
|
|
<h3>Create File</h3>
|
|
<pre><code>cat > newfile.txt
|
|
(type content)
|
|
Ctrl+D</code></pre>
|
|
<p>Create new file from stdin.</p>
|
|
<h3>Append to File</h3>
|
|
<pre><code>cat >> file.txt
|
|
(type content)
|
|
Ctrl+D</code></pre>
|
|
<p>Append content to file.</p>
|
|
<h3>Concatenate Files</h3>
|
|
<pre><code>cat file1.txt file2.txt > combined.txt</code></pre>
|
|
<p>Combine multiple files.</p>
|
|
<h3>Show Non-Printing</h3>
|
|
<pre><code>cat -A file.txt</code></pre>
|
|
<p>Show all characters including tabs and line endings.</p>
|
|
<h3>Pipe to Other Commands</h3>
|
|
<pre><code>cat file.txt | grep pattern</code></pre>
|
|
<p>Use cat in pipelines.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Use -n to number lines for reference</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -A to debug file formatting issues</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use > to create, >> to append</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Essential for file inspection</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Works great in pipelines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use less or more for large files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>One of the most basic Unix commands</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Perfect for quick file viewing</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|