刚刚安装了新的 Linux 发行版(new Linux distro)?您可能想知道如何在新系统上查找文件和目录。
您可以通过几种不同的方式在Linux PC 上查找文件和目录。您可以通过终端使用Linux命令(例如 find)来帮助您。或者,您可以使用Linux(Linux)发行版提供的内置文件管理工具。
如果您想在Linux(Linux)上查找文件和目录,请按照以下步骤操作。

使用查找命令
find命令是(find command)Linux中按名称查找文件和目录的最强大、最通用的工具之一。它可以根据各种条件搜索文件夹,例如文件名、所有者、文件权限、文件类型、大小或日期。
Find还可以对匹配的文件执行操作,例如删除、移动或对其执行命令。find 命令的基本语法是:
查找[选项][路径][表达式]
选项控制命令的行为方式,路径指定要搜索的起始目录或目录,而表达式由您可以使用的其他选项或操作组成(由运算符分隔)。
例如,要查找当前目录及其子目录中所有扩展名为.txt的文件,可以使用以下命令:
寻找 。-类型 f -名称“*.txt”
find后面的点(.)表示当前目录。-type f 选项指定您正在搜索常规文件。-name “* .txt ”选项匹配以(.txt).txt结尾的文件。

如果要执行不区分大小写的搜索,还可以使用 -iname 选项代替 -name。例如:
寻找 。-type f -iname“*.txt”
这将匹配以.txt(.txt)、.TXT、.Txt等结尾的文件。

find 命令具有许多有用的功能和设置,您可以通过终端 (man find) 阅读其手册页来探索这些功能和设置。一些最有用的是:
- -not:否定以下表达式。例如, -not -name “* .txt ” 匹配不以.txt结尾的文件。
- -size:按大小匹配文件。例如,-size +1M 匹配大于 1 MB 的文件。
- -mtime:按修改时间匹配文件。例如,-mtime -1匹配过去 24 小时内修改的文件。
- -exec:对每个匹配的文件执行命令。例如,-exec rm {};删除每个匹配的文件。
使用定位命令
locate 命令是在Linux(Linux)中查找文件和目录的另一种方法。Locate比 find 命令更快,因为它使用先前构建的文件名和位置数据库。但是,它可能不如 find 命令那么最新,因为数据库是由 cron 作业定期更新的。
locate命令的基本语法是:
定位[选项]模式
该模式是您要在文件名中搜索的字符串。locate 命令将返回包含该模式作为子字符串的所有文件名。
例如,要查找名称中包含单词“yes”的所有文件,您可以使用以下命令:locate yes。

如果您最近更新了大量文件,并且希望在使用locate命令之前手动更新数据库,则可以通过终端运行此命令:
须藤更新数据库
您可能需要输入密码才能运行该命令。

与 find 一样,您可以通过终端使用手册页检查用于定位的其他选项 (manlocate)。这些包括:
- -i:匹配模式时忽略大小写。例如,-i linux 匹配Linux、LINUX、 linux 等。
- -c:计算匹配文件的数量而不是显示它们。例如,-c linux 显示有多少个文件的名称中包含 linux。
- -l:将匹配文件的数量限制为指定数量。例如,-l 10 linux 仅显示名称中包含 linux 的前 10 个文件。
使用 GUI 文件管理应用程序
如果您更喜欢在Linux(Linux)中使用图形界面查找文件和目录,则可以使用Linux发行版中附带的文件管理应用程序。这可能称为Nautilus、Files或File Manager,具体取决于您使用的是 Ubuntu(using Ubuntu)还是其他 Linux 发行版。
这些应用程序允许您使用熟悉的基于窗口的界面浏览和搜索文件和目录。您可以使用侧边栏、工具栏或面包屑导航浏览文件系统。您还可以使用键盘快捷键或拖放对文件和目录执行各种操作。
要使用通用文件应用程序搜索文件和目录,您可以使用工具栏中的搜索框或按Ctrl+F。这将打开一个搜索面板,您可以在其中输入搜索条件。

您还可以按类型、大小或日期过滤结果。在Ubuntu上的文件(Files)中,按搜索结果旁边的向下箭头以选择搜索条件。

您的文件管理应用程序将在主区域中显示所有匹配的文件和目录。然后,只要您具有必要的文件权限,您就可以双击任何文件或目录将其打开或使用右键单击菜单对其执行其他操作(necessary file permissions)。
在 Linux 上管理文件
对于初学者来说,在Linux(Linux)中查找文件和目录可能是一项艰巨的任务。通过使用 find 和locate Linux命令,或者使用Linux系统的文件管理工具,您可以按各种条件搜索文件和目录并对它们执行操作。例如,您可以删除 Linux PC 上(delete files on your Linux PC)不需要的文件。
您可以尝试的另一项任务是在 Linux 上重命名文件和文件夹(renaming your files and folders on Linux),以便更轻松地找到最重要的文件。
How to Find Files and Directories in Linux
Just installed а new Linux distro? You might wonder how to find files and directories on your new system.
There are a few different ways you can find files and directories on a Linux PC. You can use Linux commands via the terminal, such as find, to help you. Alternatively, you can use the built-in file management tool provided by your Linux distro.
If you want to find files and directories on Linux, follow the steps below.

Using the Find Command
The find command is one of the most powerful and versatile tools for finding files and directories by name in Linux. It can search your folders for various criteria, such as the filename, owner, file permissions, file type, size, or date.
Find can also perform actions on the matched files, such as deleting, moving, or executing commands on them. The basic syntax of the find command is:
find [options] [path] [expression]
Options controls how the command behaves, path specifies the starting directory or directories to search, while expression consists of additional options or actions that you can use (separated by operators).
For example, to find all files with the .txt extension in the current directory and its subdirectories, you can use this command:
find . -type f -name “*.txt”
The dot (.) after find indicates the current directory. The -type f option specifies that you’re searching for regular files. The -name “*.txt” option matches files that end with .txt.

You can also use the -iname option instead of -name if you want to perform a case-insensitive search. For example:
find . -type f -iname “*.txt”
This will match files that end with .txt, .TXT, .Txt, etc.

The find command has a number of useful features and settings that you can explore by reading its manual page via the terminal (man find). Some of the most useful ones are:
- -not: Negates the following expression. For example, -not -name “*.txt” matches files that don’t end with .txt.
- -size: Matches files by size. For example, -size +1M matches files that are larger than 1 megabyte.
- -mtime: Matches files by modification time. For example, –mtime -1 matches files that were modified within the last 24 hours.
- -exec: Executes a command on each matched file. For example, -exec rm {} ; deletes each matched file.
Using the Locate Command
The locate command is another way to find files and directories in Linux. Locate is faster than the find command because it uses a previously built database of file names and locations. However, it may not be as up-to-date as the find command because the database is updated periodically by a cron job.
The basic syntax of the locate command is:
locate [options] pattern
The pattern is a string of characters that you want to search for in the file names. The locate command will return all file names that contain the pattern as a substring.
For example, to find all files that contain the word “yes” in their names, you can use this command: locate yes.

If you’ve recently updated a large number of files and you want to update the database manually before using the locate command, you can run this command via the terminal:
sudo updatedb
You may need to enter your password to run the command.

Like find, you can check for additional options for locate using the manual page via the terminal (man locate). These include:
- -i: Ignores case when matching patterns. For example, -i linux matches Linux, LINUX, linux, etc.
- -c: Counts the number of matching files instead of displaying them. For example, -c linux shows how many files contain linux in their names.
- -l: Limits the number of matching files to a specified number. For example, -l 10 linux shows only the first 10 files that contain linux in their names.
Using the GUI File Management App
If you prefer a graphical interface for finding files and directories in Linux, you can use the file management app that’s included with your Linux distribution. This might be called Nautilus, Files, or File Manager, depending on whether you’re using Ubuntu or another Linux distribution.
These apps allow you to browse and search your files and directories using a familiar window-based interface. You can navigate through your file system using the sidebar, toolbar, or breadcrumbs. You can also use keyboard shortcuts or drag-and-drop to perform various actions on your files and directories.
To search for files and directories using the common file app, you can use the search box in the toolbar or press Ctrl+F. This will open a search panel where you can enter your search criteria.

You’ll also be able to filter the results by type, size, or date. In Files on Ubuntu, press the downwards arrow next to the search results to choose your search criteria.

Your file management app will display all of the matching files and directories in the main area. You can then double-click on any file or directory to open it or perform other actions on it using the right-click menu, as long as you have the necessary file permissions.
Managing Files on Linux
Finding files and directories in Linux can be a daunting task for beginners. By using the find and locate Linux commands, or by using your Linux system’s file management tool, you can search for files and directories by various criteria and perform actions on them. For instance, you can delete files on your Linux PC that you don’t need.
Another task you could try is renaming your files and folders on Linux to make it easier to locate your most important files.