2013-04-25 104 views
0

所以基本上我需要找到自己的GitHub項目中的所有文件和文件夾包含字符串「人」git的發現和重命名多個文件名和文件夾名稱

find . -type f -print | grep "persons" 
find . -type d -print | grep "persons" 

上述工作對我來說是字符串。

But I also need to rename all the above files and folders with 'members' 

我可以通過幾條命令來完成上述操作嗎?不用手動替換它們由一個 一個我不知道如何做一個混帳MV oldfilename newfilename rescursively上述

回答

1
for dir in `find /DIR -type d -iname '*persons*'` ; do 
    git mv "${dir}" "${dir/persons/members}" 
done 

就行了。對於這些文件,請使用-type f

+0

這可以用在git的上下文嗎? – Micheal 2013-04-25 19:25:13

+0

答覆已更新。 – 2013-04-25 19:44:39

+0

它有點不工作。我在我的終端上得到一個dquote。我也不需要提交命令太 – Micheal 2013-04-25 21:29:08

0
find . -depth -name persons | while read F; do mv $F $(dirname $F)/members; done 
+0

這隻會移動'個人'文件/目錄,而不是那些匹配模式的文件/目錄。並跳過git部分。 – 2013-04-25 19:43:39

相關問題