Tuesday, 23 May 2017

How to rename a group of filename on unix?


a) put the file name in to a .sh, each line just put one file name, and make sure there is
   no empty line.
b) :%s#\(.*\)#rename \1 prefix_\1_suffix#g
   or b) :%s#\(.*\)#mv \1 prefix_\1_suffix#g    (if you get error: Bareword "some_word" not allowed while "strict subs" in use at (eval 1) line number.)
c) edit the name to what you like, e.g, here I have to change *_119793 to *, I first change them all to *_1197938888, and then search _1197938888 and delete these suffix all.
d) then change mode to the script and run it. (chmod 777 rename.sh)

$ cat  ~/bin/rename.sh
mv bindings_119793 bindings
mv cmake_119793 cmake
mv CMakeCache.txt_119793 CMakeCache.txt
mv CMakeFiles_119793 CMakeFiles
mv CMakeLists.txt_119793 CMakeLists.txt
mv CODE_OWNERS.TXT_119793 CODE_OWNERS.TXT
mv configure_119793 configure
mv CPackConfig.cmake_119793 CPackConfig.cmake
mv CPackSourceConfig.cmake_119793 CPackSourceConfig.cmake
mv CREDITS.TXT_119793 CREDITS.TXT
mv docs_119793 docs
mv examples_119793 examples
mv include_119793 include
mv lib_119793 lib
mv LICENSE.TXT_119793 LICENSE.TXT
mv LLVMBuild.txt_119793 LLVMBuild.txt
mv llvm.spec.in_119793 llvm.spec.in
mv projects_119793 projects
mv README.txt_119793 README.txt
mv RELEASE_TESTERS.TXT_119793 RELEASE_TESTERS.TXT
mv resources_119793 resources
mv runtimes_119793 runtimes
mv temp_52476 temp_524768888
mv test_119793 test
mv tools_119793 tools
mv unittests_119793 unittests
mv utils_119793 utils

No comments:

Post a Comment