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 @ 2020-07-24 14:40  Leonardo-li  阅读(364)  评论(0编辑  收藏  举报