5290589 发表于 2018-8-29 07:27:20

"shell in" & "find exclude"

  find 转 http://blog.csdn.net/ysdaniel/article/details/7995681
  查找cache目录下不是html的文件

[*]  find ./cache ! -name '*.html' -type f
  列出当前目录下的目录名,排除includes目录,后面的-print不能少

[*]  find . -path './includes' -prune -o -type d -maxdepth 1 -print
  排除多个目录,”(“前是带”\”的

[*]  find / path/home/opath/root -prune -nouser -type f -exec ls -l {} \;
find查找文件的时候排除某个或几个文件或目录
  比如要在/usr/sam目录下查找不在dir1子目录之内的所有文件
  find /usr/sam -path "/usr/sam/dir1" -prune -o -print
  find [-path ..] 在路径列表的后面的是表达式
  -path "/usr/sam" -prune -o -print 是 -path "/usr/sam" -a -prune -o
-print 的简写表达式按顺序求值, -a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果 -path
"/usr/sam" 为真,则求值 -prune , -prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假。如果
-path "/usr/sam" -a -prune 为假,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值-print,或逻辑表达式为真。
  这个表达式组合特例可以用伪码写为
  if -path "/usr/sam" then
  -prune
  else
  -print
  避开多个文件夹
  find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print
  圆括号表示表达式的结合。
  \ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。
  查找某一确定文件,-name等选项加在-o 之后
  #find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print
  linux下的常用命令find,加上不同的参数,可以使你很容易的找到需要的文件,但是有些时候,你在查找文件的同时,可能不需要在某文件夹下查找,这时候-prune就用上了。
  比如在当前目录下寻找pl后缀的文件,不在scripts下寻找。
  find . -path './scripts' -prune -o -name '*.pl' -print
  shell in 转http://bbs.chinaunix.net/thread-3737652-1-1.html
#! /bin/bash  
var=$1
  

  
list="01 02 03"
  
if [[ " $list " =~ " $var " ]]#注意 $list 和 $var 两边的空格
  
then
  
echo match
  
fi
#!/bin/sh  

  
ex_path="01 02 03"
  

  
path=`ls ./`
  

  

  
for i in ${path[@]};do
  
if[[ " $ex_path " =~ " $i " ]];then
  
    echo "ok" > /dev/null
  
else
  
    find ./$i -name "*.php"|xargs grep -E "v7\.|v71\." >> /tmp/tmp.txt
  
fi
  
done


页: [1]
查看完整版本: "shell in" & "find exclude"