2015年11月4日 星期三

[linux] find move specific file to new directory 使用 find ,xargs 搬移特定檔案到新資料夾



使用了

asciidoc gen 了某個資料夾樹狀結構下的所有 asciidoc 成 html 檔案。


find ./ -name "*.asciidoc" | xargs -n 1 asciidoc


$ tree -d ./
./
├── aggregations
│   ├── bucket
│   └── metrics
├── docs
└── query-dsl

看了一下他們目錄結構

想要把產生的html 檔都移到同樣結構下的資料夾去

1.先建立起對應的資料夾

find ./java-api -name "*.html" | xargs -n 1 dirname | sort -u | xargs -I d echo java-api_html/d | xargs -n 1 mkdir -p

 java-api_html 這是我要集中放置 html 檔案的資料夾
xargs -I  是接一個replstr 一個替代後面參數使用的字串

-I replstr
             Execute utility for each input line, replacing one or more occurrences of replstr in up to replacements (or 5 if no -R flag is
             specified) arguments to utility with the entire line of input.  The resulting arguments, after replacement is done, will not be
             allowed to grow beyond 255 bytes; this is implemented by concatenating as much of the argument containing replstr as possible, to
             the constructed arguments to utility, up to 255 bytes.  The 255 byte limit does not apply to arguments to utility which do not con-
             tain replstr, and furthermore, no replacement will be done on utility itself.  Implies -x.


2. 搬移檔案到已經建立好的資料夾去

find ./java-api -name "*.html" | xargs -I f mv f ./java-api_html/f


這樣就大功告成了

沒有留言:

張貼留言