如何在Linux中搜索文件和路径

huangapple go评论89阅读模式
英文:

How to Search for file and path in Linux

问题

我怎么搜索文件并打印出它们的目录。
我一直在尝试
ls -R | grep "filename.txt"
但它只打印出文件名。如何修改这个命令以打印出文件的路径,或者是否有任何命令?
谢谢您。

英文:

How can i search files and print out their directory.
I have been trying
ls -R | grep "filename.txt"
however it only prints out the filename. How can i modify this command to printout the path of the file or is their any command
Thankyou

答案1

得分: 1

你可以在终端中使用“find”命令。

示例:find -name filename.txt

您可以定义一个起始搜索的目录:

示例:find /path/to/start -name filename.txt

您还可以查找匹配的模式:

示例:find -name "*.txt"

使用 / 会搜索整个文件系统,但这可能会给您的计算机带来较重的负担:

示例:find / -name filename.txt

英文:

you can use the "find" command in the terminal.

Ex: find -name filename.txt

You can define a directory to start the search:

Ex: find /path/to/start -name filename.txt

You can also find match a pattern:

Ex: find -name "*.txt"

Using a / will search the entire file system, but this can cause a heavy load on your computer:

Ex: find / -name filename.txt

huangapple
  • 本文由 发表于 2023年8月5日 08:42:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76839731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定