如何从 Linux 终端找到特定文件?

发布于 2024-12-05 02:02:39 字数 1559 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

往事风中埋 2024-12-12 02:02:39

从根路径查找 find / -name "index.html"

从当前路径查找 find 。 -名称“index.html”

Find from root path find / -name "index.html"

Find from current path find . -name "index.html"

熊抱啵儿 2024-12-12 02:02:39

下面的代码行将为您完成。

find / -name index.html

但是,在大多数 Linux 服务器上,您的文件将位于 /var/www 或用户目录文件夹 /home/(user) 中,具体取决于您的设置方式向上。如果您使用控制面板,它很可能位于您的用户文件夹下。

The below line of code would do it for you.

find / -name index.html

However, on most Linux servers, your files will be located in /var/www or in your user directory folder /home/(user) depending on how you have it set up. If you're using a control panel, most likely it'll be under your user folder.

陈独秀 2024-12-12 02:02:39

试试这个(通过 shell):

update db
locate index.html

或者:

find /var -iname "index.html"

用你对它所在目录的最佳猜测替换 /var,但避免从 / 开始

Try this (via a shell):

update db
locate index.html

Or:

find /var -iname "index.html"

Replace /var with your best guess as to the directory it is in but avoid starting from /

萌化 2024-12-12 02:02:39

解决方案:使用unix命令find

查找实用程序递归地向下查找每个路径的目录树
列出,评估一个表达式(由 'primaries' 和
'操作数')就
树中的每个文件。

  • 您可以通过控制它来使查找操作更加高效和智能
    正则表达式查询、文件类型、大小阈值、深度
    子树、组、所有权、时间戳、修改/创建日期等维度。
  • 此外,您可以使用运算符并组合查找请求,例如
    或/不/和等等...

传统的公式将是:

find <path> -flag <valueOfFlag>

简单示例

1.按名称查找 - 查找所有包.json 来自我当前位置子树层次结构。

find . -name "package.json"

2.按名称和类型查找 - 从所有文件系统中查找所有node_modules目录(从根层次结构开始)

sudo find / -name "node_modules" -type d

复杂示例:

更多有用的示例可以展示标志选项和运算符的强大功能:

3.正则表达式和文件类型 - 仅在我的应用程序位置查找所有 javascript 控制器变体名称(使用正则表达式)javascript 文件

find /user/dev/app -name "*contoller-*\.js" -type f

-type f 表示与正则表达式相关的文件 -name 到控制器字符串和破折号的任何变体与 .js 4.

深度 - 查找应用目录中的所有路线模式目录不超过3个维度 (app/../../ ..仅且不再更深)

find app -name "*route*" -type d  -maxdepth 3

-type d 表示与正则表达式相关的目录 -name 到路由字符串 -max深度 的任何变体,使查找器专注于 3 个子树深度,而不再< code>/深度1/深度2/深度3)

5.文件大小、所有权和 OR 运算符 - 查找 root 所有权下名称为“sample”或“test”的所有文件大于1的用户兆和小于 5 兆。

find . \( -name "test" -or -name "sample" \)  -user root -size +1M -size -5M

-size 阈值,表示大于 (+) 和小于 (-) 之间的范围 -user 表示文件所有者 -or 运算符过滤两个正则表达式匹配的查询

6.空文件 - 查找文件系统中的所有空目录

find / -type d -empty

7.时间访问、修改和创建文件 - 查找所有创建/修改/访问的文件10 天内的目录

# creation (c)
find /test -name "*.groovy" -ctime -10d
# modification (m)
find /test -name "*.java" -mtime -10d
# access (a)
find /test -name "*.js" -atime -10d

8.修改大小过滤器 - 查找一周前到三周前修改过且小于 500kb 的所有文件,并以列表形式显示其大小

find /test -name "*.java" -mtime -3w -mtime +1w -size -500k | xargs du -h

Solution: Use unix command find

The find utility recursively descends the directory tree for each path
listed, evaluating an expression (composed of the 'primaries' and
'operands') in terms of
each file in the tree.

  • You can make the find action be more efficient and smart by controlling it with
    regular expressions queries, file types, size thresholds, depths
    dimensions in subtree, groups, ownership, timestamps , modification/creation date and more.
  • In addition you can use operators and combine find requests such as
    or/not/and etc...

The Traditional Formula would be :

find <path> -flag <valueOfFlag>

Easy Examples

1.Find by Name - Find all package.json from my current location subtree hierarchy.

find . -name "package.json"

2.Find by Name and Type - find all node_modules directories from ALL file system (starting from root hierarchy )

sudo find / -name "node_modules" -type d

Complex Examples:

More Useful examples which can demonstrate the power of flag options and operators:

3.Regex and File Type - Find all javascript controllers variation names (using regex) javascript Files only in my app location.

find /user/dev/app -name "*contoller-*\.js" -type f

-type f means file -name related to regular expression to any variation of controller string and dash with .js at the end

4.Depth - Find all routes patterns directories in app directory no more than 3 dimensions ( app/../../.. only and no more deeper)

find app -name "*route*" -type d  -maxdepth 3

-type d means directory -name related to regular expression to any variation of route string -maxdepth making the finder focusing on 3 subtree depth and no more <yourSearchlocation>/depth1/depth2/depth3)

5.File Size , Ownership and OR Operator - Find all files with names 'sample' or 'test' under ownership of root user that greater than 1 Mega and less than 5 Mega.

find . \( -name "test" -or -name "sample" \)  -user root -size +1M -size -5M

-size threshold representing the range between more than (+) and less than (-) -user representing the file owner -or operator filters query for both regex matches

6.Empty Files - find all empty directories in file system

find / -type d -empty

7.Time Access, Modification and creation of files - find all files that were created/modified/access in directory in 10 days

# creation (c)
find /test -name "*.groovy" -ctime -10d
# modification (m)
find /test -name "*.java" -mtime -10d
# access (a)
find /test -name "*.js" -atime -10d

8.Modification Size Filter - find all files that were modified exactly between a week ago to 3 weeks ago and less than 500kb and present their sizes as a list

find /test -name "*.java" -mtime -3w -mtime +1w -size -500k | xargs du -h
森罗 2024-12-12 02:02:39

查找 /the_path_you_want_to_find -name index.html

find /the_path_you_want_to_find -name index.html

一曲琵琶半遮面シ 2024-12-12 02:02:39

一般来说,在任意位置查找任何文件的最佳方法是启动终端窗口并输入经典的 Unix 命令“find”:

find / -name index.html -print

因为您要查找的文件是 Web 根目录中的根文件服务器,可能更容易找到 Web 服务器的文档根目录。例如,查看:

/var/www/*

或键入:

find /var/www -name index.html -print

In general, the best way to find any file in any arbitrary location is to start a terminal window and type in the classic Unix command "find":

find / -name index.html -print

Since the file you're looking for is the root file in the root directory of your web server, it's probably easier to find your web server's document root. For example, look under:

/var/www/*

Or type:

find /var/www -name index.html -print
生来就爱笑 2024-12-12 02:02:39

我们有2个选项,一个是find命令,另一个是locate命令

Find Command
如果您的文件是index.html

sudo find / -name index.html(如果您知道路径,请替换而不是/)

则需要sudo

如果您在根访问文件夹中搜索locate命令,

定位命令将保存单独的数据库来运行。

ex

如果您的文件找不到, 请定位index.html
运行以下命令

sudo updateb

now 尝试定位index.html

注意:locate 更快,因为它使用 db 而不是直接文件系统搜索,

但从我的角度来看,find 命令很好,因为它搜索整个文件系统。

希望你能出点好主意。

There are 2 options we have, one is find command and another is locate command

Find Command
if your file is index.html

sudo find / -name index.html (if you know the path pls replace instead of /)

sudo is required if you are searching in root access folders

locate command

locate command will hold the separate db to run.

ex: locate index.html

if your file is not able to find
run the following command

sudo updatedb

now try to locate index.html

Note: locate is faster because it uses db instead of a direct file system search

But from my point of view find command is good, because it is searching the entire file system.

Hope you go some good idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文