find 的搬移方法 - Linux

Rebecca avatar
By Rebecca
at 2011-03-31T14:39

Table of Contents

※ 引述《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/ {} +

--

人不作出犧牲,便得不到任何收穫;如果要得到某種東西,就必須付出同等代價。這一點
,就是鍊金術的基本原則 ── 等價交換。當時我們深信這一點就是世界的真理。

阿爾風斯‧愛力克,《鋼之鍊金術師》開場白

--
Tags: Linux

All Comments

Lauren avatar
By Lauren
at 2011-04-05T12:41
感謝!!了解了
Anthony avatar
By Anthony
at 2011-04-09T10:31
喔喔~ 受教了

CallGraphviz – call graph visualzer

Skylar DavisLinda avatar
By Skylar DavisLinda
at 2011-03-31T10:08
圖文: http://bit.ly/etmDwY [2]CallGraphviz – call graph visualzer based on csope, graphviz and xdot = 開源工具現狀 = 許多開發者都有從中介入中大型專案的經驗,常必須試圖理解原始程式的設計,或多或少 都有在 ...

選購筆電希望安裝(CentOS)

Hazel avatar
By Hazel
at 2011-03-31T00:48
※ 引述《alohaiscool (aloha)》之銘言: : 如題 : 小弟乃Linux初心者 : 未來想要往server那邊學習(所以選擇CentOS) : 剛好有需要買筆電 想說乾脆灌Linux : 目前網路上查到的資源如下 : http://wiki.centos.org/HowTos/Laptop ...

選購筆電希望安裝(CentOS)

Ethan avatar
By Ethan
at 2011-03-30T15:37
如題 小弟乃Linux初心者 未來想要往server那邊學習(所以選擇CentOS) 剛好有需要買筆電 想說乾脆灌Linux 目前網路上查到的資源如下 http://wiki.centos.org/HowTos/Laptops 現在看來就是Aspire或Eee Pc 但是我比較中意的是Le ...

關於Grub的安裝問題

Hazel avatar
By Hazel
at 2011-03-30T14:53
用Debian啟動 (這時BIOS應該是設定成B開機,因為grub在B MBR) 在Debian裡頭使用grub shell,你需要知道A和C /boot對應的(hdX,X)是多少,見鳥哥 假設找到A是(hd0,0), C /boot是(hd2,0),接下來 grubandgt; root (hd2,0) [ ...

rsync 備份 /

Olive avatar
By Olive
at 2011-03-30T14:45
目前我有兩顆硬碟各一個partition / 跟 /home 如果我用rsync 備份 / (不跨過 /home) 然後假使 / 這顆壞掉了 我想拿備份來用 我可以直接設定 boot sector 就可以拿他來開機了嗎? 那要怎麼設定? - ...