2015年9月22日 星期二

[Linux 常見問題] exclude directory from find command

Source From Here 
Question 
I'm trying to run a find command for all javascript files, but I need to exclude a specific directory. Here is the find code we're using. 
  1. for file in $(find . -name '*.js'); do java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file; done  
How-To 
Use the prune switch, for example if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command: 
// expr1 -o expr2: Or; expr2 is not evaluated if expr1 is true.
# find . -path ./misc -prune -o -name '*.txt' -print

Here is an example with multiple directories: 
# find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

Here we exclude dir1dir2 and dir3, since in find expressions it is an action, that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d. Further action is -o print, just print. 

Supplement 
35 Practical Examples of Linux Find Command

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...