find 的搬移方法 - Linux

By Rebecca
at 2011-03-31T14:39
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/ {} +
--
人不作出犧牲,便得不到任何收穫;如果要得到某種東西,就必須付出同等代價。這一點
,就是鍊金術的基本原則 ── 等價交換。當時我們深信這一點就是世界的真理。
阿爾風斯‧愛力克,《鋼之鍊金術師》開場白
--
: 標題: 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

By Lauren
at 2011-04-05T12:41
at 2011-04-05T12:41

By Anthony
at 2011-04-09T10:31
at 2011-04-09T10:31
Related Posts
CallGraphviz – call graph visualzer

By Skylar DavisLinda
at 2011-03-31T10:08
at 2011-03-31T10:08
選購筆電希望安裝(CentOS)

By Hazel
at 2011-03-31T00:48
at 2011-03-31T00:48
選購筆電希望安裝(CentOS)

By Ethan
at 2011-03-30T15:37
at 2011-03-30T15:37
關於Grub的安裝問題

By Hazel
at 2011-03-30T14:53
at 2011-03-30T14:53
rsync 備份 /

By Olive
at 2011-03-30T14:45
at 2011-03-30T14:45