linux按名称查找文件_如何在Linux中按名称查找文件?

linux按名称查找文件

linux按名称查找文件

Linux provides different tools to find files for different attributes. We can find files according to their size, name, modification time location, etc. But one of the most used metrics is finding file according to its name. In this tutorial, we will look at different tools to find files by name in Linux.

Linux提供了不同的工具来查找具有不同属性的文件。 我们可以根据文件的大小,名称,修改时间位置等找到文件。但是最常用的指标之一是根据文件的名称查找文件。 在本教程中,我们将介绍在Linux中按名称查找文件的不同工具。

使用find命令查找文件 (Find Files with find Command)

find  is the most feature-full tool to find files according to its name. find provides a lot more features which can be examined in the following tutorial.

find是功能最齐全的工具,可根据其名称查找文件。 find提供了更多功能,可以在以下教程中进行研究。

Linux Find Command With Examples

Linux使用示例查找命令

We will use -name  option which is used to specify the file name we search. In this example we will look file named db.conf  in this example.

我们将使用-name选项,该选项用于指定我们搜索的文件名。 在此示例中,我们将在此示例中查找名为db.conf文件。

$ find . -name db.conf
Using find
Using find
使用查找

查找不区分大小写的文件(Find Files As Caseinsensitive)

In previous example we have searched in a case sensitive manner. Case sensitive will only list same case names. For example if we search for db.conf  it will only match db.conf  contained name but will not match DB.conf or similar. We disable case sensitivity and match DB.conf too with the -iname as we ca see just prefixing with i . In this example we will search caseinsenstive.

在前面的示例中,我们以区分大小写的方式进行搜索。 区分大小写只会列出相同的案例名称。 例如,如果我们搜索db.conf ,它将仅匹配db.conf包含的名称,而不会匹配DB.conf或类似名称。 我们禁用了区分大小写的功能,并且也将DB.conf-iname因为我们看到的只是以i DB.conf 。 在此示例中,我们将搜索不敏感的案例。

$ find . -iname db.conf
Using find Caseinsenstive
Using find Caseinsenstive
使用查找Caseinsenstive

查找特定位置的文件 (Find Files For Specific Location)

We can also specify the location we can search. In previous example we have already specified the location by using dot which means the current working path. We can put other path. In this example, we will search in /home/ismail

我们还可以指定我们可以搜索的位置。 在前面的示例中,我们已经通过使用点指定了位置,这意味着当前的工作路径。 我们可以另辟path径。 在此示例中,我们将在/home/ismail搜索

$ find /home/ismail -name db.conf
Specifying Location
Specifying Location
指定位置

使用locate命令查找文件(Find Files Using locate Command)

Locate is a very fast and useful tool. locate will search its database and try to match the given term. locate will match the all name and path for the given term we can only look for the name with -b option. This will only match file or folder name not the whole path. In this example we will search for db.conf .

定位是一个非常快速且有用的工具。 定位将搜索其数据库并尝试匹配给定的术语。 查找将匹配给定术语的所有名称和路径,我们只能使用-b选项查找名称。 这只会匹配文件或文件夹名称,而不匹配整个路径。 在此示例中,我们将搜索db.conf

$ locate -b db.conf
Using locate
Using locate
使用定位

使用ls和更少的命令查找文件(Find Files Using ls and less Commands)

There is also a bit different and interesting way to search for files. ls command is used to list files and directories. We can also use ls recursively where we can list sub files and directories too. We will redirect the ls output to the less command. Then we will use less search function which is run with / to search in the output.

搜索文件还有另一种有趣的方式。 ls命令用于列出文件和目录。 我们还可以递归使用ls,在这里我们也可以列出子文件和目录。 我们将ls输出重定向到less命令。 然后,我们将使用less搜索功能,该功能与/一起运行,以在输出中进行搜索。

$ ls -R /home/ismail | less

then search db.conf with the following command in the less screen.

然后在以下屏幕中使用以下命令搜索db.conf

/db.conf
Using ls and less
Using ls and less
使用ls和更少
LEARN MORE  How To Change File and Directory Permissions with Chmod Recursively
了解更多如何使用Chmod递归更改文件和目录权限

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

linux按名称查找文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值