linux按目录名查找目录 您所在的位置:网站首页 find寻找目录 linux按目录名查找目录

linux按目录名查找目录

2024-07-09 16:35| 来源: 网络整理| 查看: 265

linux按目录名查找目录

linux按目录名查找目录

Linux provides different ways to find directories. Here we will look at how to find directories in a recursive way. In this tutorial, we will use commands like  find and locate.

Linux提供了多种查找目录的方法。 在这里,我们将研究如何以递归方式查找目录。 在本教程中,我们将使用诸如find和locate类的命令。

使用find命令查找目录和文件 (Find Directories and Files with find Command)

Find command is a popular command to used a lot of different purposes like find file and directory, take a backup, copy files. Actually find do not have these abilities it just runs commands over search results like copy and backup.

查找命令是一种流行的命令,用于许多不同的目的,例如查找文件和目录,进行备份,复制文件。 实际上发现它没有这些功能,它只是对搜索结果(如复制和备份)运行命令。

Syntax

句法

find LOCATION SEARCH_TERM ACTION `LOCATION` is the path or location we will search in

“ LOCATION”是我们将在其中搜索的路径或位置 `SEARCH_TERM` is the term which is the file or directory name we want to search

“ SEARCH_TERM”是我们要搜索的文件或目录名称的术语`ACTION` is optional which can take actions like print, delete, rename in the search results

“ ACTION”是可选的,可以在搜索结果中执行打印,删除,重命名等操作

We will search for a directory bin in the root file system.

我们将在根文件系统中搜索目录bin。

$ find / -name bin Find Command Find Command 查找命令 获取有关目录和文件的详细信息(Get Detailed Information about The Directories and Files)

We can get detailed information about found directories by using -ls parameter for the find command.

通过为find命令使用-ls参数,可以获取有关找到的目录的详细信息。

$ find / -name bin -ls Get Detailed Information Get Detailed Information 获取详细信息

Here results will list the size of the directory permission of the directory, owner, last change date, etc.

这里的结果将列出目录的目录权限大小,所有者,上次更改日期等。

仅列出目录 (Only List Directories)

Up to now, we have searched for all files and directories. We can search for only directories by providing a type parameter with a directory specifier.

到目前为止,我们已经搜索了所有文件和目录。 我们可以通过为类型参数提供目录说明符来仅搜索目录。

$ find / -name bin -ls -type d Only List Directories Only List Directories 仅列出目录 定位(Locate)

Locate command is a non-interactive alternative to find command. Also, locate have restricted capabilities. The advantage of the locate command is that it is fast because locate use database to search. Manually a database for file and directories is created. Manually this database is updated. The search is done directly in this database. Database is located at /var/lib/mlocate/mlocate.db.

查找命令是查找命令的一种非交互方式。 此外,查找具有受限功能。 locate命令的优点是它很快,因为locate使用数据库进行搜索。 手动创建用于文件和目录的数据库。 手动更新此数据库。 搜索直接在此数据库中完成。 数据库位于/var/lib/mlocate/mlocate.db 。

We will update our database to search with locate command. To update the locate database we need root privileges.

我们将更新数据库以使用locate命令进行搜索。 要更新定位数据库,我们需要root特权。

$ sudo updatedb

We will search for files and directories ends with /bin. In this example, we will use the regex option of the locate to specify the end of the line.

我们将搜索以/bin结尾的文件和目录。 在此示例中,我们将使用定位的regex选项指定行的结尾。

$ locate --regex /bin$ Locate Locate 定位 LEARN MORE  How To Use Regular Expression - Regex In Bash Linux? 了解更多信息如何在Bash Linux中使用正则表达式-Regex?

翻译自: https://www.poftut.com/find-directory-linux/

linux按目录名查找目录



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有