简述linux文件搜索 linuxsir_org.htm

来自「linuxSir 网站的精华文章」· HTM 代码 · 共 393 行 · 第 1/2 页

HTM
393
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://www.linuxsir.org/main/?q=node/208 -->
<HTML lang=zh-hans xml:lang="zh-hans" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>简述Linux文件搜索 | LinuxSir.Org</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css media=all>@import url( misc/drupal.css );
</STYLE>


<STYLE type=text/css media=all>@import url( modules/taxonomy_context/taxonomy_context.css );
</STYLE>
<LINK media=screen href="简述Linux文件搜索  LinuxSir_Org.files/menuExpandable3.css" 
type=text/css rel=stylesheet>
<SCRIPT src="简述Linux文件搜索  LinuxSir_Org.files/menuExpandable3.js" 
type=text/javascript></SCRIPT>
<LINK href="简述Linux文件搜索  LinuxSir_Org.files/common.css" type=text/css 
rel=stylesheet>
<STYLE type=text/css media=all>@import url( themes/chameleon/marvin/style.css );
</STYLE>

<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY>
<DIV id=header><A title=Home href="http://www.linuxsir.org/main/"><IMG alt=Home 
src="简述Linux文件搜索  LinuxSir_Org.files/logo.jpg"></A></DIV>
<DIV class=navlinks>
<DIV class=primary><A href="http://www.linuxsir.org/main/?q"><FONT 
color=white>首页</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/34"><FONT 
color=white>事件</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/"><FONT 
color=white>文档</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/"><FONT 
color=white>资源</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=search"><FONT color=white>搜索</FONT></A> | 
<A href="http://www.linuxsir.org/bbs"><FONT color=white>论坛</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/38"><FONT 
color=white>贡献者</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=node/3"><FONT color=white>关于</FONT></A> | 
<A href="http://www.linuxsir.org/main/?q=user"><FONT 
color=white>注册/登录</FONT></A></DIV></DIV>
<TABLE id=content>
  <TBODY>
  <TR>
    <TD id=sidebar-left>
      <DIV class="block block-block" id=block-block-1>
      <H2 class=title>子站索引</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://fedora.linuxsir.org/" target?_blank?>Fedora中文</A> 
        <LI><A href="http://debian.linuxsir.org/" target?_blank?>Debian中文</A> 
        <LI><A href="http://lfs.linuxsir.org/" target?_blank?>LFS 中文</A> 
        <LI><A href="http://slack.linuxsir.org/">Slackware</A> 
        <LI><A href="http://gentoo.linuxsir.org/">Gentoo中文</A> 
        <LI><A href="http://arch.linuxsir.org/">Arch 中文</A> </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-3>
      <H2 class=title>重要资讯</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/36">本站公告</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/34">新闻事件</A> 
        <LI><A href="http://www.linuxsir.org/bbs" target=_blank>本站论坛</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/38">贡 献 者</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-7>
      <H2 class=title>项目索引</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.fcitx.org/" target=_blank>小企鹅输入法</A> 
        <LI><A href="http://lumaqq.linuxsir.org/" target=_blank>LumaQQ</A> 
        <LI><A href="http://openq.linuxsir.org/" target=_blank>OpenQ</A> 
        <LI><A href="http://www.relaxbsd.org/" target=_blank>RelaxBSD</A> 
      </LI></UL></DIV></DIV>
      <DIV class="block block-user" id=block-user-1>
      <H2 class=title>站点导航</H2>
      <DIV class=content>
      <DIV class=menu>
      <UL>
        <LI class=leaf><A title=注册/登录 
        href="http://www.linuxsir.org/main/?q=user">注册/登录</A> 
        <LI class=collapsed><A 
        href="http://www.linuxsir.org/main/?q=aggregator">新闻聚合</A> 
      </LI></UL></DIV></DIV></DIV>
      <DIV class="block block-aggregator" id=block-aggregator-feed-2>
      <H2 class=title>LinuxSir.Org 论坛</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=266922&amp;goto=newpost">如何在FvwmButtons中使用系统托盘?</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=266921&amp;goto=newpost">FC5 
        root 的垃圾箱被彻底删掉了,怎么恢复?</A> 
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=266920&amp;goto=newpost">我想做一个mini 
        linux 该怎么下手呢~</A> 
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=266919&amp;goto=newpost">FC5体验之影音篇</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=266918&amp;goto=newpost">请教高手:FEDORA 
        4 安装问题</A> </LI></UL></DIV>
      <DIV class=more-link><A title=查看此feed的最新消息 
      href="http://www.linuxsir.org/main/?q=aggregator/sources/2">更多</A></DIV></DIV></DIV>
      <DIV class="block block-user" id=block-user-2>
      <H2 class=title>最新注册</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI>horiwa
        <LI>jiechu
        <LI>emiss
        <LI>ismart
        <LI>mynamewsy</LI></UL></DIV></DIV></DIV>
      <DIV class="block block-user" id=block-user-3>
      <H2 class=title>当前在线</H2>
      <DIV class=content>0 users 和 66 游客 在线</DIV></DIV></TD>
    <TD id=main>
      <DIV class=breadcrumb><A href="http://www.linuxsir.org/main/?q=">首页</A> » 
      <A href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A></DIV>
      <H2>简述Linux文件搜索</H2><!-- begin content -->
      <DIV class=node>
      <DIV class=content>
      <P><B>作者:</B>北南南北<BR><B>来自:</B>LinuxSir.Org<BR><B>摘要:</B>本文简单介绍了搜索文件的方法,一是通过文件名来查看文件所处的位置,二是在一个文件或输出中查找指定的内容。</P>
      <P><FONT size=4><B>目录</B></FONT></P>
      <UL><A href="http://www.linuxsir.org/main/?q=node/208#1">1 
        、关于搜索;</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/208#2">2、通过搜索文件名来查找文件;</A>
        <P></P>
        <UL><A href="http://www.linuxsir.org/main/?q=node/208#2.1">2.1 find 
          ;</A><BR><A href="http://www.linuxsir.org/main/?q=node/208#2.2">2.2 
          locate </A><BR><A 
          href="http://www.linuxsir.org/main/?q=node/208#2.3">2.3 whereis 
          和which</A>
          <P></P>
          <UL><A href="http://www.linuxsir.org/main/?q=node/208#2.3.1">2.3.1 
            where</A><BR><A 
            href="http://www.linuxsir.org/main/?q=node/208#2.3.2">2.3.2 which 
            </A></UL></UL>
        <P><A 
        href="http://www.linuxsir.org/main/?q=node/208#3">3、在一个文件或输出中查找;</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/208#4">4、关于本文;</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/208#5">5、参考文档;</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/208#6">6、相关文档;</A> </P></UL>
      <P><FONT 
      color=blue><B><BR>+++++++++++++++++++++++++++++++++++++++<BR>正文<BR>+++++++++++++++++++++++++++++++++++++++<BR></B></FONT></P>
      <P><FONT id=1 size=4><B><BR>1 、关于搜索;<BR></B></FONT></P>
      <P>在Linux文件系统中,搜索概念有两种,一种是搜索文件名,另一种是在一个文件中搜索指定的内容;这两种搜索,我们都简要的介绍一下,但不一定极为专业。想到哪写到哪;</P>
      <P><FONT id=2 size=4><B><BR>2、通过搜索文件名来查找文件;<BR></B></FONT></P>
      <P>有的弟兄经常会说文件都放在哪里了,我怎么查找文件?其实这里说的意思就是通过文件名来查找文件所处的位置;搜索文件名,我们常用的工具有find、locate、where等。现在我们简单的说一说这几个工具在文件系统中,通过查找文件名的方法来查看其所在的位置;</P>
      <P><FONT id=2.1 size=3><B><BR>2.1 find ;<BR></B></FONT></P>
      <P>
      <DIV class=codeblock><CODE>find 路径 -name 文件名</CODE></DIV>
      <P></P>
      <P><B>举例:</B>比如在/etc中搜索vsftpd.conf文件;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# find /etc -name 
      vsftpd.conf</CODE></DIV><BR><BR><BR><B>find 更为详细的说明请参考:</B> <A 
      href="http://www.linuxsir.org/main/?q=node/137"><B>《Linux文件查找命令find,xargs详述》</B></A>
      <P></P>
      <P>find 是最强劲的搜索工具,用法也比较灵活,而不是仅仅找一个文件名这个功能。</P>
      <P><FONT id=2.2 size=3><B><BR>2.2 locate<BR></B></FONT></P>
      <P>locate 是用来通过文件名搜索文件的工具,它的用法也比较简单。locate 
      的应用,首先要通过updatedb建立索引数据库,然后才能应用;如果您新安装了软件或者存放了新的文件,也要先运行updatedb命令,以生成最新索引库。</P>
      <P><B>用法:</B></P>
      <P>
      <DIV class=codeblock><CODE>locate 文件名</CODE></DIV>
      <P></P>
      <P>我们要先运行updatedb;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# updatedb</CODE></DIV>
      <P></P>
      <P><B>举例:</B> 我们要找vsftpd.conf文件都位于哪个位置;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# locate 
      vsftpd.conf<BR>/etc/vsftpd/vsftpd.conf<BR>/home/beinan/vsftpd.conf<BR>/root/.vsftpd.conf.swp<BR>/root/vsftpd.conf<BR>/root/vsftpd.config<BR>/usr/share/doc/vsftpd-2.0.4/EXAMPLE/INTERNET_SITE/vsftpd.conf<BR>/usr/share/doc/vsftpd-2.0.4/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf<BR>/usr/share/doc/vsftpd-2.0.4/EXAMPLE/VIRTUAL_USERS/vsftpd.conf<BR>/usr/share/logwatch/default.conf/logfiles/vsftpd.conf<BR>/usr/share/logwatch/default.conf/services/vsftpd.conf<BR>/usr/share/man/man5/vsftpd.conf.5.gz</CODE></DIV>
      <P></P>
      <P><FONT id=2.3 size=3><B><BR>2.3 whereis 和which<BR></B></FONT></P>
      <P><FONT id=2.3.1 size=2><B><BR>2.3.1 where<BR></B></FONT></P>
      <P>whereis 是来寻找命令的二进制文件,同时也会找到其帮助文件;</P>
      <P>比如我们不知道fdisk工具放在哪里,我们就可以用whereis fdisk 来查找;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# whereis fdisk<BR>fdisk: 
      /sbin/fdisk /usr/share/man/man8/fdisk.8.gz</CODE></DIV>
      <P></P>
      <P>如果我们寻找grub在哪里,应该用如下命令,说明grub位于/sbin目录,他的帮助文件是grub.8.gz ,也就是man 
grub;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# whereis grub<BR>grub: 
      /sbin/grub /etc/grub.conf /usr/share/grub 
      /usr/share/man/man8/grub.8.gz</CODE></DIV>
      <P></P>
      <P><FONT id=2.3.2 size=2><B><BR>2.3.2 which<BR></B></FONT></P>
      <P>which 和where 相似,只是我们所设置的环境变量中设置好的路径中寻找;比如;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# which 
      fdisk<BR>/sbin/fdisk</CODE></DIV>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?