Git recursive mv files

我怕爱的太早我们不能终老 提交于 2019-12-13 19:19:23

问题


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.


回答1:


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' _ {} +


来源:https://stackoverflow.com/questions/22623921/git-recursive-mv-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!