程式扎記: [Linux 常見問題] exclude directory from find command

標籤

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

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!