Find and replace filename recursively in a directory

前端 未结 14 1780
野趣味
野趣味 2020-11-28 21:24

I want to rename all the files in a folder which starts with 123_xxx.txt to xxx.txt.

For example, my directory has:

123_xxx         


        
相关标签:
14条回答
  • 2020-11-28 22:23

    Here's the only solution to date that works:

    find-rename-recursive --pattern '123_' --string '' -- . -type f -name "123_*"
    

    All other solutions don't work for me--some even deleted files!

    For details, see https://github.com/l3x/helpers#find-rename-recursive

    0 讨论(0)
  • 2020-11-28 22:25
    find -name "123*.txt" -exec rename 's/^123_//' {} ";" 
    

    will do it. No AWK, no for, no xargs needed, but rename, a very useful command from the Perl lib. It is not always included with Linux, but is easy to install from the repos.

    0 讨论(0)
提交回复
热议问题