Re: [問題] find 的搬移方法

看板Linux作者 (三十個扮上進青年之一)時間14年前 (2011/03/31 14:39), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《aeolus0829 (archer)》之銘言: : 標題: Re: [問題] find 的搬移方法 : 時間: Thu Mar 31 13:19:52 2011 : : ※ 引述《human45 (昨日小篤)》之銘言: : : ->aaa 沒搬過去,test2 反倒被嘗試搬過來 test1 底下....囧 : : 我的想法是,exec mv 時的來源路徑應當是 regex 得到的路徑(./test1/aaa), : : 所以我後面是直接接目的路徑(./test2/) : : 請問我是哪邊搞錯了= =? : : 感謝! : : 順序錯了 : find . -regex "\.\/test[12]\/a+" -exec mv {} test2/ + : : 說明: {} 是用來放 find 找到的東西 : 推 human45:囧....我想說我問題沒說明清楚想重打的說.... 03/31 13:23 : → human45:執行結果 "find: ‘-exec’ 後缺少了參數" 03/31 13:24 : → human45:可以在請問後面那個 "+" 有甚麼作用嗎? 03/31 13:26 : → human45:真的很抱歉..因為老師來了...我先去上課,等等回來討論= = 03/31 13:27 前些時候好像有同學討論過 find 的 "+" 使用方式了,自已還有些疑惑, 所以把這個問題翻找了一下: 在 man page 裡面的說明是~ -exec command {} + This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invoca- tions of the command will be much less than the number of matched files. The command line is built in much the same way that xargs builds its command lines. Only one instance of `{}' is allowed within the command. The command is executed in the starting directory. 意即是,如果使用 "+" 在 find 命令裡頭,會串接這些搜尋結果在 command 的最後面 例如: $ find . -name "*.mp3" -exec mplayer {} + 執行上會等同是: mplayer 1.mp3 2.mp3 3.mp3 4.mp3 # 這樣一行下完 所以會上面 find . -regex "\.\/test[12]\/a+" -exec mv {} test2/ + 的結果 應該會出問題。 結論: 因為 mv 的限制 a. 應該還是用 \; 每行命令隔開。 b. 或著用 mv -t test2/ {} + -- 人不作出犧牲,便得不到任何收穫;如果要得到某種東西,就必須付出同等代價。這一點 ,就是鍊金術的基本原則 ── 等價交換。當時我們深信這一點就是世界的真理。 阿爾風斯‧愛力克,《鋼之鍊金術師》開場白 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.237.56

03/31 15:51, , 1F
感謝!!了解了
03/31 15:51, 1F

04/01 08:32, , 2F
喔喔~ 受教了
04/01 08:32, 2F
文章代碼(AID): #1Db26UFh (Linux)
文章代碼(AID): #1Db26UFh (Linux)