当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - Renaming all the folders centos

问题描述:

can anyone tell me how to rename all the folders in a directory from terminal?

every folder is in format of "id-namestring", is there any way to rename using this pattern to remove everything after "id" in the folder name?

for example if folder name is "123-abcd&efg" it should be renamed to "123"

网友答案:
find top-level-dir -type d -print0 | xargs -0 rename 's/(\d+)-.+/$1/'

This will rename all the directories (-type d) contained in the directory top-level-dir.

xargs is used to cope with the case of very long list of files. -print0 and -0 is for the case when your file names contain spaces.

s/(\d+)-.+/$1/ is the actual regexp used for renaming.

网友答案:

you can use Perl expression if you feel comfortable with this.

in this link you can find an overview of rename command with this perl expressions

分享给朋友:
您可能感兴趣的文章:
随机阅读: