Rename multiple Folders in Linux rekursive at the same location as source folder

Hi Folks,

 

I had a short issue with rename multiple folders under Linux at the same location.

As we all know the mv command require a source and a new location.

Bbut what should we do if we want to search for folder name and rename all founded?

I had trouble to get the rename at the location where the folder were found.

In my case I want to rename folders named by name of month (January February and so on) to the number of month (01, 02 …).

So the solution for this case is the execdir option from find.

If you would try it with exec you will not reach your goal but with execdir it is working fine.

Problem

chris@Kubuntu-Laptop:~$ ls test/*
test/2011:
feb jan mar


test/2012:
feb jan mar


test/2013:
feb jan mar


test/2014:
feb jan mar


test/2015:
feb jan mar

so that was my issue and now I want to rename all jan folder into 01 and all feb into 02 and so on ..

Solution

find /home -type d -iname jan -execdir mv {} 01 \;

and then the directory looks like this:

chris@Kubuntu-Laptop:~$ ls test/*
test/2011:
01 feb mar

test/2012:
01 feb mar

test/2013:
01 feb mar

test/2014:
01 feb mar

test/2015:
01 feb mar

so this was what I want, so I reach my goal. If you like you can run this into a loop for all month changes at once or run it 12 times for 12 month names.

br

Chris

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.