Linux 查找文件位置
要素:
find 命令:
用于搜索给定目录树中的文件和目录。
-name 参数:
指定要查找的文件名。
-type 参数:
指定要查找的文件类型,如文件、目录、符号链接等。
-path 参数:
指定要查找的文件的路径。
-exec 命令;
在找到文件后执行指定的命令。
-print0 参数:
将搜索结果以空字符分隔输出,便于进一步处理。
示例:
查找名为 "example.txt" 的文件:
find / -name example.txt
查找名为 "example.txt" 的文件,并打印其绝对路径:
find / -name example.txt -exec echo {} \;
查找名为 "example.txt" 的文件,并执行 "ls -l" 命令:
find / -name example.txt -exec ls -l {} \;
查找名为 "example.txt" 的文件,并输出其搜索结果到 "results.txt" 文件:
find / -name example.txt -print0 | xargs -0 -n1 -I {} echo {} >> results.txt