Bash rename extension recursive

后端 未结 6 1581
-上瘾入骨i
-上瘾入骨i 2020-12-29 09:32

I know there are a lot of things like this around, but either they don\'t work recursively or they are huge.

This is what I got:

find . -name \"*.so\         


        
6条回答
  •  悲哀的现实
    2020-12-29 09:57

    A bash script to rename file extensions generally

      #/bin/bash
      find -L . -type f -name '*.'$1 -print0 | while IFS= read -r -d '' file; do
          echo "renaming $file to $(basename ${file%.$1}.$2)";
          mv -- "$file" "${file%.$1}.$2";
      done
    

    Credits to aps2012.

    Usage

    1. Create a file e.g. called ext-rename (no extension, so you can run it like a command) in e.g. /usr/bin (make sure /usr/bin is added to your $PATH)
    2. run ext-rename [ext1] [ext2] anywhere in terminal, where [ext1] is renaming from and [ext2] is renaming to. An example use would be: ext-rename so dylib, which will rename any file with extension .so to same name but with extension .dylib.

提交回复
热议问题