<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>ikn0w1T&#039;s blog - linux</title>
<link>https://blog.lihan.cyou/index.php/tag/linux/</link>
<atom:link href="https://blog.lihan.cyou/index.php/feed/tag/linux/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Wed, 09 Jul 2025 18:48:00 +0800</lastBuildDate>
<pubDate>Wed, 09 Jul 2025 18:48:00 +0800</pubDate>
<item>
<title>find命令小记</title>
<link>https://blog.lihan.cyou/index.php/archives/158/</link>
<guid>https://blog.lihan.cyou/index.php/archives/158/</guid>
<pubDate>Wed, 09 Jul 2025 18:48:00 +0800</pubDate>
<dc:creator>ikn0w1T</dc:creator>
<description><![CDATA[find命令小记1. 按文件名查找查找当前目录及其子目录下所有名为example.txt的文件find . -name &quot;example.txt&quot;. 表示从当前目录开始查找。...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h1>find命令小记</h1><h3>1. 按文件名查找</h3><h4>查找当前目录及其子目录下所有名为<code>example.txt</code>的文件</h4><pre><code class='language-shell' lang='shell'>find . -name &quot;example.txt&quot;
</code></pre><ul>
<li><code>.</code> 表示从当前目录开始查找。</li>
<li><code>-name</code> 指定文件名匹配条件。</li>

</ul><h4>查找当前目录及其子目录下所有以<code>.log</code>结尾的文件</h4><pre><code class='language-shell' lang='shell'>find . -name &quot;*.log&quot;
</code></pre><ul>
<li><code>*</code> 是通配符，表示匹配任意字符。</li>

</ul><h3>2. 按文件类型查找</h3><h4>查找当前目录及其子目录下所有的目录</h4><pre><code class='language-shell' lang='shell'>find . -type d
</code></pre><ul>
<li><code>-type d</code> 表示查找目录。</li>

</ul><h4>查找当前目录及其子目录下所有的普通文件</h4><pre><code class='language-shell' lang='shell'>find . -type f
</code></pre><ul>
<li><code>-type f</code> 表示查找普通文件。</li>

</ul><h3>3. 按文件大小查找</h3><h4>查找当前目录及其子目录下所有大于1MB的文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -size +1M
</code></pre><ul>
<li><code>-size +1M</code> 表示文件大小大于1MB。</li>

</ul><h4>查找当前目录及其子目录下所有小于1KB的文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -size -1k
</code></pre><ul>
<li><code>-size -1k</code> 表示文件大小小于1KB。</li>

</ul><h3>4. 按修改时间查找</h3><h4>查找当前目录及其子目录下最近7天内修改过的文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -mtime -7
</code></pre><ul>
<li><code>-mtime -7</code> 表示文件在过去7天内被修改过。</li>

</ul><h4>查找当前目录及其子目录下超过30天未修改的文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -mtime +30
</code></pre><ul>
<li><code>-mtime +30</code> 表示文件在过去30天内未被修改过。</li>

</ul><h3>5. 按权限查找</h3><h4>查找当前目录及其子目录下所有权限为755的文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -perm 755
</code></pre><ul>
<li><code>-perm 755</code> 表示文件权限为<code>rwxr-xr-x</code>。</li>

</ul><h4>查找当前目录及其子目录下所有可执行文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -executable
</code></pre><ul>
<li><code>-executable</code> 表示文件具有可执行权限。</li>

</ul><h3>6. 组合条件查找</h3><h4>查找当前目录及其子目录下所有大于1MB且在过去7天内修改过的文件</h4><pre><code class='language-shell' lang='shell'>find . -type f -size +1M -mtime -7
</code></pre><ul>
<li>多个条件可以组合使用。</li>

</ul><h3>7. 执行操作</h3><h4>查找当前目录及其子目录下所有<code>.log</code>文件并删除</h4><pre><code class='language-shell' lang='shell'>find . -name &quot;*.log&quot; -exec rm -f {} \;
</code></pre><ul>
<li><code>-exec</code> 后面跟要执行的命令，<code>{}</code> 表示当前匹配的文件名。</li>
<li><code>\;</code> 表示命令结束。</li>

</ul><h4>查找当前目录及其子目录下所有<code>.txt</code>文件并打印其内容</h4><pre><code class='language-shell' lang='shell'>find . -name &quot;*.txt&quot; -exec cat {} \;
</code></pre><ul>
<li>使用 <code>cat</code> 命令打印文件内容。</li>

</ul><h3>8. 排除特定目录</h3><h4>查找当前目录及其子目录下所有文件，但排除<code>node_modules</code>目录</h4><pre><code class='language-shell' lang='shell'>find . -path &quot;./node_modules&quot; -prune -o -print
</code></pre><ul>
<li><code>-path</code> 指定要排除的路径。</li>
<li><code>-prune</code> 表示跳过该路径。</li>
<li><code>-o</code> 表示逻辑“或”。</li>

</ul><h3>9. 按用户或组查找</h3><h4>查找当前目录及其子目录下所有属于用户<code>john</code>的文件</h4><pre><code class='language-shell' lang='shell'>find . -user john
</code></pre><ul>
<li><code>-user</code> 指定文件的所有者。</li>

</ul><h4>查找当前目录及其子目录下所有属于组<code>users</code>的文件</h4><pre><code class='language-shell' lang='shell'>find . -group users
</code></pre><ul>
<li><code>-group</code> 指定文件所属的组。</li>

</ul><h3>10. 按深度查找</h3><h4>查找当前目录下（不包括子目录）所有文件</h4><pre><code class='language-shell' lang='shell'>find . -maxdepth 1
</code></pre><ul>
<li><code>-maxdepth</code> 指定最大搜索深度。</li>

</ul>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://blog.lihan.cyou/index.php/archives/158/#comments</comments>
<wfw:commentRss>https://blog.lihan.cyou/index.php/feed/tag/linux/</wfw:commentRss>
</item>
</channel>
</rss>