linux 查找文件夹命令_如何从命令行在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定位
- grepgrep
- which 哪一个
- whereis哪里
查找命令(Find Command)
find
command 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
文件。 我们将使用全球范围内搜索词的开头和结尾,以便接受搜索词的任何前缀或后缀。 因此,这将匹配conffff
, myconf
, myconfffff
, myconfiguration.txt
等。
$ find . -type f -name "*conf*"
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 Folders)
We may need only to find the folder. We will specify the type like below a directory.
我们可能只需要找到该文件夹。 我们将在目录下指定类型。
$ find . -type d -name "*conf*"
查找命令(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
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
命令以及文件和文件夹名称进行搜索。
$ locate /home/ismail/*back*
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
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
哪个命令(Which Command)
which
command 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 查找文件夹命令