SonicProtein
SonicProtein

Reputation: 850

Rename bulk directories but keeping a part of the original directory name linux

I have a few directories with names like:

test_1
test_23
test_4
test_19
test_15

And I wish to rename them

test_name_1
test_name_23
test_name_4
test_name_19
test_name_15

So just adding name_ in the directory name, but keeping the same number on the end.

I thought the rename command might work, but don't know how to keep a part of the original name the same?

Upvotes: 1

Views: 49

Answers (1)

whoan
whoan

Reputation: 8531

You can accomplish it with rename as you supposed:

rename test_ test_name_ test_[0-9]*

The test_ part is the pattern to find; test_name_ is the replacement; test_[0-9]* filters the files you want to rename.

Upvotes: 2

Related Questions