239 lines
7.1 KiB
HTML
239 lines
7.1 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>find 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">find 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>find searches for files and directories in a directory hierarchy. Powerful tool for locating files by name, type, size, modification time, and more.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>find /path -name "pattern" - Find by name</li>
|
|
</ul>
|
|
<ul>
|
|
<li>find . -type f - Find files only</li>
|
|
</ul>
|
|
<ul>
|
|
<li>find . -type d - Find directories only</li>
|
|
</ul>
|
|
<ul>
|
|
<li>find . -name "*.txt" - Find by extension</li>
|
|
</ul>
|
|
<ul>
|
|
<li>find /path -exec command {} \; - Execute command</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Search by Name</h2>
|
|
<ul>
|
|
<li>-name "pattern" - Exact name match</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-iname "pattern" - Case-insensitive name</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-path "pattern" - Match path</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-regex pattern - Regular expression</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Search by Type</h2>
|
|
<ul>
|
|
<li>-type f - Files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-type d - Directories</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-type l - Symbolic links</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-type b - Block devices</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-type c - Character devices</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-type p - Named pipes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-type s - Sockets</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Search by Size</h2>
|
|
<ul>
|
|
<li>-size +100M - Larger than 100MB</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-size -10k - Smaller than 10KB</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-size 50c - Exactly 50 bytes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-empty - Empty files/directories</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Search by Time</h2>
|
|
<ul>
|
|
<li>-mtime -7 - Modified in last 7 days</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-mtime +30 - Modified more than 30 days ago</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-atime -1 - Accessed in last 24 hours</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-ctime -2 - Changed in last 2 days</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-newer file - Newer than file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-amin -60 - Accessed in last 60 minutes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-mmin -30 - Modified in last 30 minutes</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Search by Permissions</h2>
|
|
<ul>
|
|
<li>-perm 644 - Exact permissions</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-perm -u+w - User has write</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-perm /o+x - Others have execute</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-user username - Owned by user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-group groupname - Owned by group</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Actions</h2>
|
|
<ul>
|
|
<li>-print - Print results (default)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-ls - List like ls -dils</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-delete - Delete found files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-exec command {} \; - Execute command</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-exec command {} + - Execute with multiple files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-ok command {} \; - Interactive exec</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Find by Name</h3>
|
|
<pre><code>find . -name "*.txt"</code></pre>
|
|
<p>Find all .txt files.</p>
|
|
<h3>Find Large Files</h3>
|
|
<pre><code>find / -size +100M</code></pre>
|
|
<p>Find files larger than 100MB.</p>
|
|
<h3>Find Recent Files</h3>
|
|
<pre><code>find . -mtime -7</code></pre>
|
|
<p>Files modified in last week.</p>
|
|
<h3>Find and Delete</h3>
|
|
<pre><code>find . -name "*.tmp" -delete</code></pre>
|
|
<p>Delete all .tmp files.</p>
|
|
<h3>Find and Execute</h3>
|
|
<pre><code>find . -name "*.sh" -exec chmod +x {} \;</code></pre>
|
|
<p>Make scripts executable.</p>
|
|
<h3>Find Empty Files</h3>
|
|
<pre><code>find . -type f -empty</code></pre>
|
|
<p>Find empty files.</p>
|
|
<h3>Find by User</h3>
|
|
<pre><code>find /home -user username</code></pre>
|
|
<p>Find files owned by user.</p>
|
|
<h3>Find Directories</h3>
|
|
<pre><code>find . -type d -name "config"</code></pre>
|
|
<p>Find directories named config.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Use -name for simple patterns</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -iname for case-insensitive</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -type to filter file types</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -size to find large/small files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -mtime for time-based searches</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Be careful with -delete</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -exec for batch operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Essential for file system management</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|