linux文件查找工具

复制代码
 1 #!/bin/sh
 2 # lazy find
 3 
 4 # GNU All-Permissive License
 5 # Copying and distribution of this file, with or without modification,
 6 # are permitted in any medium without royalty provided the copyright
 7 # notice and this notice are preserved.  This file is offered as-is,
 8 # without any warranty.
 9 
10 ## help function
11 
12 function helpu {
13     echo " "
14     echo "Fuzzy search for filename."
15     echo "$0 [--match-case|--path] filename"
16     echo " "
17     exit
18 }
19 
20 ## set variables
21 
22 MATCH="-iname"
23 SEARCH="."
24 
25 ## parse options
26 
27 while [ True ]; do
28 if [ "$1" = "--help" -o "$1" = "-h" ]; then
29     helpu
30 elif [ "$1" = "--match-case" -o "$1" = "-m" ]; then
31     MATCH="-name"
32     shift 1
33 elif [ "$1" = "--path" -o "$1" = "-p" ]; then
34     SEARCH="${2}"
35     shift 2
36 else
37     break
38 fi
39 done
40 
41 ## sanitize input filenames
42 ## create array, retain spaces
43 
44 ARG=( "${@}" ) 
45 set -e
46 
47 ## catch obvious input error
48 
49 if [ "X$ARG" = "X" ]; then
50     helpu
51 fi
52 
53 ## perform search
54 
55 for query in ${ARG[*]}; do
56     /usr/bin/find "${SEARCH}" "${MATCH}" "*${ARG}*"
57 done
复制代码

 

posted @   Leonardo-li  阅读(365)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
点击右上角即可分享
微信分享提示