Git的递归MV文件 [英] Git recursive mv files
问题描述
我想版本号添加到所有的JavaScript文件的目录,以便更改这些文件不会被我们的用户进行高速缓存。
我怎样才能移动处于多个目录一个目录中的所有JavaScript文件?
随着示例文件结构:
JS /
- 家/
---- main.js
- 应用/
---- main.js
--handlers.js
--ajax.js
我愿做类似 git的MV -r JS / *。JS JS / *。1.js
追加一个 .1
的文件名。显然,不是递归git的MV标志,所以我想知道我的选择是做类似的事情。
的 Globstar (庆典> = 4)
禁用了javascript -s globstar#设置shell选项globstar
在** / * JS楼;做
Git的MV$ F$ {F%的.js} $ version.js
DONE
要移动的一切单个目录:
在** / * JS源。做
DEST =$ {源%的.js} $ version.js
DEST =$目的地/ $ {DEST ## * /}#剥去领先的目录和prePEND实际目标
git的MV$源,$ DEST
DONE
查找
您可以使用找到
,但它几乎是相同的,所以保存这在您需要的Bash 3或POSIX sh的可移植性(OS X,例如)。
找到。 -iname'* .js文件'-exec SH -c'为F;做
Git的MV$ F$ {F%的.js} $ version.js
做'_ {} +
I'm trying to add version numbers to all javascript files in a directory so that changes to the files won't be cached by our users.
How can I move all Javascript files that are in several directories within one directory?
With the example file structure:
js/
--home/
----main.js
--apps/
----main.js
--handlers.js
--ajax.js
I would like to do something like git mv -r js/*.js js/*.1.js
to append a .1
to the filenames. Obviously there isn't a flag for recursion for git mv, so I'm wondering what my options are to do something similar.
Globstar (bash >=4)
shopt -s globstar # Set the SHell OPTion globstar
for f in **/*.js; do
git mv "$f" "${f%.js}.$version.js"
done
To move everything to a single directory:
for source in **/*.js; do
dest="${source%.js}.$version.js"
dest="$destination/${dest##*/}" # Strip off leading directories and prepend actual destination
git mv "$source" "$dest"
done
Find
You can use find
, but it's almost the same, so save this for where you need Bash 3 or POSIX sh portability (OS X, for example).
find . -iname '*.js' -exec sh -c 'for f; do
git mv "$f" "${f%.js}.$version.js"
done' _ {} +
这篇关于Git的递归MV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!