Rename files and directories recursively under ubuntu /bash

后端 未结 8 1166
执念已碎
执念已碎 2020-11-29 18:50

I want to rename all files and directories that contain the word \"special\" to \"regular\". It should maintain case sensitivity so \"Special\" won\'t become \"regular\".

8条回答
  •  感动是毒
    2020-11-29 19:49

    Try doing this (require bash --version >= 4):

    shopt -s globstar
    rename -n 's/special/regular/' **
    

    Remove the -n switch when your tests are OK

    warning There are other tools with the same name which may or may not be able to do this, so be careful.

    If you run the following command (GNU)

    $ file "$(readlink -f "$(type -p rename)")"
    

    and you have a result like

    .../rename: Perl script, ASCII text executable
    

    and not containing:

    ELF
    

    then this seems to be the right tool =)

    If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :

    $ sudo update-alternatives --set rename /path/to/rename
    

    (replace /path/to/rename to the path of your perl's rename command.


    If you don't have this command, search your package manager to install it or do it manually


    Last but not least, this tool was originally written by Larry Wall, the Perl's dad.

提交回复
热议问题