• cat nginx.log|grep "Oct/2020"|grep "index.html">grep.log
  • linux查找文件夹命令Most peopleuse a graphical file manager to find files in Linux, such as Nautilus in Gnome, Dolphin in KDE, and Thunar in Xfce. However, there are several ways to use the command ...



    Most people use a graphical file manager to find files in Linux, such as Nautilus in Gnome, Dolphin in KDE, and Thunar in Xfce. However, there are several ways to use the command line to find files in Linux, no matter what desktop manager you use.

    大多数人使用图形文件管理器在Linux中查找文件,例如Gnome中的Nautilus,KDE中的Dolphin和Xfce中的Thunar。 但是,无论使用哪种桌面管理器,都有几种方法可以使用命令行在Linux中查找文件。


    使用查找命令 (Using the Find Command)

    The “find” command allows you to search for files for which you know the approximate filenames. The simplest form of the command searches for files in the current directory and recursively through its subdirectories that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria.

    “ find”命令使您可以搜索已知文件名的文件。 该命令的最简单形式是在当前目录中搜索文件,并通过与提供的搜索条件相匹配的子目录递归搜索。 您可以按名称,所有者,组,类型,权限,日期和其他条件搜索文件。

    Typing the following command at the prompt lists all files found in the current directory.


    find .

    The dot after “find” indicates the current directory.



    To find files that match a specific pattern, use the -name argument. You can use filename metacharacters (such as * ), but you should either put an escape character ( \ ) in front of each of them or enclose them in quotes.

    要查找与特定模式匹配的文件,请使用-name参数。 您可以使用文件名元字符(例如* ),但应在每个字符前放置转义符( \ )或将其括在引号中。

    For example, if we want to find all the files that start with “pro” in the Documents directory, we would use the cd Documents/ command to change to the Documents directory, and then type the following command:

    例如,如果我们要在Documents目录中找到所有以“ pro”开头的文件,则可以使用cd Documents/命令切换到Documents目录,然后键入以下命令:

    find . -name pro\*

    All files in the current directory starting with “pro” are listed.

    列出当前目录中以“ pro”开头的所有文件。

    NOTE: The find command defaults to being case sensitive. If you want the search for a word or phrase to be case insensitive, use the -iname option with the find command. It is the case insensitive version of the -name command.

    注意:find命令默认为区分大小写。 如果要搜索的单词或短语不区分大小写,请在find命令中使用-iname选项。 它是-name命令的不区分大小写的版本。


    If find doesn’t locate any files matching your criteria, it produces no output.


    The find command has a lot of options available for refining the search. For more information about the find command, run man find  in a Terminal window and press Enter.

    find命令具有许多可用于完善搜索的选项。 有关find命令的更多信息,请在“终端”窗口中运行man find并按Enter。

    使用定位命令 (Using the Locate Command)

    The locate command is faster than the find command because it uses a previously built database, whereas the find command searches in the real system, through all the actual directories and files. The locate command returns a list of all path names containing the specified group of characters.

    find命令比find命令快,因为它使用以前建立的数据库,而find命令在真实系统中搜索所有实际目录和文件。 查找命令返回包含指定字符组的所有路径名的列表。

    The database is updated periodically from cron, but you can also update it yourself at any time so you can obtain up-to-the-minute results. To do this, type the following command at the prompt:

    该数据库是通过cron定期更新的,但是您也可以随时自己更新它,以便获得最新的结果。 为此,在提示符下键入以下命令:

    sudo updatedb

    Enter your password when prompted.



    The basic form of the locate command finds all the files on the file system, starting at the root, that contain all or any part of the search criteria.


    locate mydata

    For example, the above command found two files containing “mydata” and one file containing “data.”

    例如,上述命令找到了两个包含“ mydata”的文件和一个包含“ data”的文件。


    If you want to find all files or directories that contain exactly and only your search criteria, use the -b option with the locate command, as follows.


    locate -b ‘\mydata’

    The backslash in the above command is a globbing character, which provides a way of expanding wildcard characters in a non-specific file name into a set of specific filenames. A wildcard is a symbol that can be replaced by one or more characters when the expression is evaluated. The most common wildcard symbols are the question mark ( ? ), which stands for a single character and the asterisk ( * ), which stands for a contiguous string of characters. In the above example, the backslash disables the implicit replacement of “mydata” by “*mydata*” so you end up with only results containing “mydata.”

    上面命令中的反斜杠是通配符,它​​提供了一种将非特定文件名中的通配符扩展为一组特定文件名的方法。 通配符是一种符号,在计算表达式时可以用一个或多个字符替换。 最常见的通配符是问号( ? )代表单个字符,而星号( * )代表连续的字符串。 在上面的示例中,反斜杠禁用了用“ * mydata *”隐式替换“ mydata”,因此最终只能得到包含“ mydata”的结果。


    The mlocate command is a new implementation of locate. It indexes the entire file system, but the search results only include files to which the current user has access. When you update the mlocate database, it keeps timestamp information in the database. This allows mlocate to know if the contents of a directory changed without reading the contents again and makes updates to the database faster and less demanding on your hard drive.

    mlocate命令是locate的新实现。 它为整个文件系统建立索引,但是搜索结果仅包括当前用户有权访问的文件。 当您更新mlocate数据库时,它将时间戳信息保留在数据库中。 这使mlocate无需重新读取目录内容即可知道目录的内容是否已更改,并且使对数据库的更新更快,对硬盘的要求更低。

    When you install mlocate, the /usr/bin/locate binary file changes to point to mlocate. To install mlocate, if it’s not already included in your Linux distribution, type the following command at the prompt.

    安装mlocate时,/ usr / bin / locate二进制文件更改为指向mlocate。 要安装mlocate,如果Linux发行版中尚未包含mlocate,请在提示符下键入以下命令。

    sudo apt-get install mlocate

    NOTE: We will show you a command later in this article that allows you to determine where the executable for a command is located, if it exists.



    The mlocate command does not use the same database file as the standard locate command. Therefore, you may want to create the database manually by typing the following command at the prompt:

    mlocate命令与标准locate命令使用的数据库文件不同。 因此,您可能需要通过在提示符下键入以下命令来手动创建数据库:

    sudo /etc/cron.daily/mlocate

    The mlocate command will not work until the database is created either manually or when the script is run from cron.



    For more information about either the locate or the mlocate command, type man locate or man mlocate  in a Terminal window and press Enter. The same help screen displays for both commands.

    有关无论是定位还是更多信息的mlocate命令,键入man locateman mlocate在终端窗口,然后按Enter。 这两个命令显示相同的帮助屏幕。

    使用哪个命令 (Using the Which Command)

    The “which” command returns the absolute path of the executable that is called when a command is issued. This is useful in finding the location of an executable for creating a shortcut to the program on the desktop, on a panel, or other place in the desktop manager. For example, typing the command which firefox displays the results shown in the image below.

    “哪个”命令返回执行命令时调用的可执行文件的绝对路径。 这对于在桌面,面板或桌面管理器中的其他位置查找用于创建程序快捷方式的可执行文件的位置很有用。 例如,键入命令which firefox显示下图所示的结果。


    By default, the which command only displays the first matching executable. To display all matching executables, use the -a option with the command:

    缺省情况下,which命令仅显示第一个匹配的可执行文件。 要显示所有匹配的可执行文件,请在命令中使用-a选项:

    which -a firefox

    You can search for multiple executables using at once, as shown in the following image. Only the paths to executables found are displayed. In the example below, only the “ps” executable was found.

    您可以一次搜索多个可执行文件,如下图所示。 仅显示找到的可执行文件的路径。 在下面的示例中,仅找到“ ps”可执行文件。


    NOTE: The which command only searches the current user’s PATH variable. If you search for an executable that is only available for the root user as a normal user, no results will display.

    注意:which命令仅搜索当前用户的PATH变量。 如果搜索仅对root用户具有普通用户身份的可执行文件,则不会显示任何结果。

    For more information about the which command, type “man which” (without the quotes) at the command prompt in a Terminal window and press Enter.

    有关which命令的更多信息,请在Terminal窗口的命令提示符下键入“ man which”(不带引号),然后按Enter。

    使用Whereis命令 (Using the Whereis Command)

    The whereis command is used to find out where the binary, source, and man page files for a command are located. For example, typing whereis firefox at the prompt displays results as shown in the following image.

    whereis命令用于查找命令的二进制文件,源文件和手册页文件的位置。 例如,在提示符下键入whereis firefox将显示结果,如下图所示。


    If you want only the path to the executable to display, and not the paths to the source and the man(ual) pages, use the -b option. For example, the command whereis -b firefox will display only /usr/bin/firefox as the result. This is handy because you will most likely search for a program’s executable file more often than you would search for source and man pages for that program. You can also search for only the source files ( -s ) or for only the man pages ( -m ).

    如果只想显示可执行文件的路径,而不要显示源页面和手册页的路径,请使用-b选项。 例如,命令whereis -b firefox将仅显示/usr/bin/firefox作为结果。 这很方便,因为与搜索该程序的源文件和手册页相比,搜索该程序的可执行文件的可能性更高。 您还可以仅搜索源文件( -s )或仅手册页( -m )。

    For more information about the whereis command, type man whereis in a Terminal window and press Enter.

    有关whereis命令的更多信息,请在Terminal窗口中键入man whereis并按Enter。

    了解Whereis命令和which命令之间的区别 (Understanding the Difference Between the Whereis Command and the Which Command)

    The whereis command shows you the location for the binary, source, and man pages for a command, whereas the which command only shows you the location of the binary for the command.


    The whereis command searches through a list of specific directories for the binary, source, and man files whereas the which command searches the directories listed in the current user’s PATH environment variable. For the whereis command, the list of specific directories can be found in the FILES section of the man pages for the command.

    whereis命令在特定目录列表中搜索二进制文件,源文件和man文件,而where命令则搜索当前用户的PATH环境变量中列出的目录。 对于whereis命令,可以在命令手册页的FILES部分中找到特定目录的列表。

    When it comes to results displayed by default, the whereis command displays everything it finds whereas the which command only displays the first executable it finds. You can change that using the -a option, discussed earlier, for the which command.

    当涉及默认显示的结果时,whereis命令显示其找到的所有内容,而which命令仅显示其找到的第一个可执行文件。 您可以使用前面讨论的-a选项针对which命令来更改它。

    Because the whereis command only uses paths hard-coded into the command, you may not always find what you are looking for. If you are searching for a program you think might be installed in a directory not listed in the man pages for the whereis command, you might want to use the which command with the -a option to find all occurrences of the command throughout the system.

    因为whereis命令仅使用硬编码到命令中的路径,所以您可能并不总是找到所需的内容。 如果您正在搜索某个程序,您认为可能会将其安装在whereis命令的手册页中未列出的目录中,则可能需要将which命令与-a选项一起使用,以查找整个系统中所有出现的命令。

    翻译自: https://www.howtogeek.com/112674/how-to-find-files-and-folders-in-linux-using-the-command-line/


  • linux 查找文件夹命令Linux provides different ways to find and locate files and folders. We can use GUI tools like GNOME and KDE file managers or other 3’rd party applications designed for finding ...
    linux 查找文件夹命令

    linux 查找文件夹命令

    Linux provides different ways to find and locate files and folders. We can use GUI tools like GNOME and KDE file managers or other 3’rd party applications designed for finding files. In this tutorial, we will look at how to find files, folders, and directories from the command line.

    Linux提供了多种查找和定位文件和文件夹的方法。 我们可以使用GNOME和KDE文件管理器之类的GUI工具,也可以使用其他旨在查找文件的第三方应用程序。 在本教程中,我们将研究如何从命令行查找文件,文件夹和目录。

    在Linux中查找文件和文件夹的工具 (Tools To Find Files and Folder In Linux)

    As stated previously there are a lot of tools that can be used to find files and folders. We will look in detail all of them. Here list of these tools.

    如前所述,有很多工具可用于查找文件和文件夹。 我们将详细介绍所有这些。 这里列出这些工具。

    • find

    • locate

    • grep

    • which

    • whereis


    查找命令(Find Command)

    findcommand is very featureful command used with a lot of different options. More details about find command can be found from the following tutorial.

    find命令是非常有特色的命令,它具有许多不同的选项。 可从以下教程中找到有关find命令的更多详细信息。

    Linux Find Command With Examples


    仅查找文件(Find Only Files)

    We can search only files by providing file type as -type f. We will search files those named conf in this example. We will use the glob start and end of the search term in order to accept any prefix or postfix for the search term. So this will match conffff, myconf, myconfffff, myconfiguration.txt etc.

    我们可以通过将文件类型设置为-type f来仅搜索文件。 在此示例中,我们将搜索名为conf文件。 我们将使用全球范围内搜索词的开头和结尾,以便接受搜索词的任何前缀或后缀。 因此,这将匹配conffffmyconfmyconfffffmyconfiguration.txt等。

    $ find . -type f -name "*conf*"
    Find Only Files
    Find Only Files

    Alternatively, we can specify the path we want to search for the given file name. We will provide the path according to .. In this example, we will search in the /etc path.

    或者,我们可以指定要搜索给定文件名的路径。 我们将根据提供路径. 。 在此示例中,我们将在/etc路径中搜索。

    $ find /etc -type f -name "*conf*"
    Find Only Files
    Find Only Files

    仅查找文件夹(Find Only Folders)

    We may need only to find the folder. We will specify the type like below a directory.

    我们可能只需要找到该文件夹​​。 我们将在目录下指定类型。

    $ find . -type d -name "*conf*"
    Find Only Folders
    Find Only Folders

    查找命令(Locate Command)

    locate command can be used as an offline database of all files and folders. locate will search a database which is created with updatedb command. More detailed information can get from the following tutorial.

    locate命令可以用作所有文件和文件夹的脱机数据库。 locate将搜索使用updatedb命令创建的数据库。 可以从以下教程中获得更多详细信息。

    locate Command Tutorial With Examples For Linux To Find Files


    LEARN MORE  How To Use Grep Command Recursively Through Sub-Directories In Linux?

    As locate database only holds file and folder names we can not search in detail. But this database provides us very fast search option then find command because it works offline.

    由于locate数据库仅包含文件和文件夹名称,因此我们无法详细搜索。 但是此数据库为我们提供了非常快速的搜索选项,然后提供了find命令,因为它可以脱机工作。

    更新数据库 (Update Database)

    As stated previously locate uses a database to search files and folders. Updating this database is important before a search. The update will take very little time.

    如前所述, locate使用数据库来搜索文件和文件夹。 搜索之前更新此数据库很重要。 更新将花费很少的时间。

    $ updatedb

    搜索文件或文件夹 (Search For File or Folders)

    We will use locate command and the file and folder name to search.


    $ locate /home/ismail/*back*
    Search For File or Folders
    Search For File or Folders

    Grep命令(Grep Command)

    grep command mainly filters given text and files contents but we can use it to find files and folders. For more detail

    grep命令主要过滤给定文本和文件内容,但是我们可以使用它来查找文件和文件夹。 欲了解更多信息

    Introduction to Linux Grep Command With Examples

    Linux Grep命令简介和示例

    We can use ls command recursively and grep the files and folder we want to find. In this example, we will search for files and folders whose names contain backup .

    我们可以递归使用ls命令,并grep我们要查找的文件和文件夹。 在此示例中,我们将搜索名称包含backup文件和文件夹。

    $ ls -R -l | grep backup
    Grep Command
    Grep Command

    哪个命令(Which Command)

    whichcommand is not an actual file and folder search. which command simply search current environment executable files. This is generally useful if we are looking for a command which is not included in PATH variable and can not use automatically.

    which命令不是实际的文件和文件夹搜索。 which命令仅搜索当前环境的可执行文件。 如果我们要寻找一个不包含在PATH变量中并且不能自动使用的命令,这通常很有用。

    $ which ls

    Whereis命令 (Whereis Command)

    whereis command is used to list given search term related binary, source, or man page files. In this example, we will search for ls binary and related man page files.

    whereis命令用于列出与给定搜索词相关的二进制,源或手册页文件。 在此示例中,我们将搜索ls二进制文件和相关的手册页文件。

    $ whereis ls

    翻译自: https://www.poftut.com/find-files-folders-directories-linux-command-line/

    linux 查找文件夹命令

  • Linux find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行...

    Linux find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。


        find -name "*.txt" 
        1.1 名称中包含tomcat
        find -name tomcat
    find -type f
    3.将目前目录及其子目录下所有最近 3 天内更新过的文件列出
    find -ctime -3
    find /var/log -type f -mtime +7 -ok rm {} \;
    find -type f -perm 644 -exec ls -l {} \;
    find / -type f -size 0 -exec ls -l {} \;


    find 根据下列规则判断 path 和 expression,在命令列上第一个 - ( ) , ! 之前的部份为 path,之后的是 expression。如果 path 是空字串则使用目前路径,如果 expression 是空字串则使用 -print 为预设 expression。
    expression 中可使用的选项有二三十个之多,在此只介绍最常用的部份。
    -mount, -xdev : 只检查和指定目录在同一个文件系统下的文件,避免列出其它文件系统中的文件
    -amin n : 在过去 n 分钟内被读取过
    -anewer file : 比文件 file 更晚被读取过的文件
    -atime n : 在过去n天内被读取过的文件
    -cmin n : 在过去 n 分钟内被修改过
    -cnewer file :比文件 file 更新的文件
    -ctime n : 在过去n天内被修改过的文件
    -empty : 空的文件-gid n or -group name : gid 是 n 或是 group 名称是 name
    -ipath p, -path p : 路径名称符合 p 的文件,ipath 会忽略大小写
    -name name, -iname name : 文件名称符合 name 的文件。iname 会忽略大小写
    -size n : 文件大小 是 n 单位,b 代表 512 位元组的区块,c 表示字元数,k 表示 kilo bytes,w 是二个位元组。-type c : 文件类型是 c 的文件。
    d: 目录
    c: 字型装置文件
    b: 区块装置文件
    p: 具名贮列
    f: 一般文件
    l: 符号连结
    s: socket
    -pid n : process id 是 n 的文件
    你可以使用 ( ) 将运算式分隔,并使用下列运算。
    exp1 -and exp2
    ! expr
    -not expr
    exp1 -or exp2
    exp1, exp2


  • linux查找文件夹

    万次阅读 2019-07-02 14:37:43
    liunx查找文件夹命令: linux查找根目录下文件夹名称叫www.buruyouni.com的目录地址 find / -name www.buruyouni.com -d 1 linux查找/var/www/目录下叫index.php的文件 find /var/www/ -name index.php 1 查找根目录...

    find / -name www.buruyouni.com  -d
    find /var/www/ -name index.php  
    find  /  -name  *.sh
    下载命令:下载 www.91cnm.com/index.php的资源
    wget  www.91cnm.com/index.php  (&下载大文件的时候加上&后台执行,断开远程连接还可以下载)
    安装软件的时候无法确认操作是否成功,如make / configure  / make install 这些命令的时候每次执行完毕可以echo $? 输出 0 则可以确认是安装成功的,输出其他的数字均表示该步骤是失败的!

  • pathname: find命令查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。-print: find命令将匹配的文件输出到标准输出。-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令...
  • 查找目录:find /(查找范围) -name ‘查找关键字’ -type d
  • linux查找文件以及文件夹命令

    千次阅读 2017-08-23 20:07:50
    find / -name xxx(xxx是文件的名字)
  • 查找目录: find /(查找范围) -name '查找关键字' -type d [root@localhost ~]# find /root/app/ -name 'temp' -type d 查找文件: find /(查找范围) -name 查找关键字 -print [root@localhost ~]# ...
  • #find -name 文件夹名称 -type d
  • 查找文件及文件夹位置 yum install -y mlocate locate 文件夹名称或文件名称 查找命令位置 which 命令名称 whereis 命令名称
  • 终端输入:locate 文件夹名  ex:想搜索lib这个文件夹在哪个位置,输入:locate lib
  • Linux 命令查找指定文件夹下符合查询条件的文件和文件夹实例演示。 演示目录结构如下: 在这里插入图片描述 查找当前文件夹下的文件和文件夹。 find -name "dimp" 查找指定文件夹下的文件和文件夹。 find /data/...
  • 查找命令: 查找根目录下查找文件夹名称叫dir的目录地址 find / -name dir -d查找/var/www/目录下叫index.jsp的文件 find /var/www/ -name index.jsp查找根目录下所有已”.sh”结尾的文件 find / -name *.sh下载...
  • linux命令查找文件及文件夹

    千次阅读 2019-04-04 10:37:07
    find命令 find /(查找范围) -name '查找关键字' eg:find / -name 'nginx' 过滤没有权限访问的文件夹,find / -name 'nginx' 2>/dev/null
  • linux find 命令查找文件和文件夹 查找目录:find /(查找范围) -name ‘查找关键字’ -type d 查找文件:find /(查找范围) -name 查找关键字 -print 根据文件或者正则表达式进行匹配 列出当前目录及子目录下所有...
  • ls | grep “ner” | ws -l ls 列出当前文件 注意:ls -l 列出详细信息(注意会多出一行) grep 正则匹配 ws 计算数量 ws -l 计算行的数量



1 2 3 4 5 ... 20
收藏数 3,474
精华内容 1,389