LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   How to rename multiple folders in 1 go? (https://www.linuxquestions.org/questions/red-hat-31/how-to-rename-multiple-folders-in-1-go-4175579493/)

sco1984 05-10-2016 11:58 PM

How to rename multiple folders in 1 go?
 
Hello,

I am using RHEL 5.7 [64bit]
I want to rename several folders which resides under 1 parent folder.

Folders as follows:

i) Maintenance-1-1_root
ii) Management-1_root

Goal: Need to remove '-1_root' suffix from all folders.

Can some1 give exact syntax to perform this task?

Thanks in advance.

Regards,
Amey.

pan64 05-11-2016 01:12 AM

have you checked the command rename?

HMW 05-11-2016 06:30 AM

Quote:

Originally Posted by sco1984 (Post 5543607)
Can some1 give exact syntax to perform this task?

Yes. But have a look here instead:
https://is.gd/eXJAXN

Try it out yourself first. If it doesn't work, get back and tell us why.

Best regards,
HMW

sco1984 05-11-2016 06:54 AM

Yes I did Google but as the server is in production env, I thought of getting advice of scripting experts out here specific to RHEL :)

HMW 05-11-2016 07:20 AM

Ok. Check out this directory:

Code:

$ ls
Maintenance-1-1_root Management-1_root foobar-1_loot foobarbaz rename_dir.sh

Now I run my script (rename_dir.sh)
Code:

$ ./rename_dir.sh
$ ls
Maintenance-1 Management foobar-1_loot foobarbaz rename_dir.sh

I did not use rename, but basename, also I used a for loop and globbing.

Give it a try!

Best regards,
HMW

Edit: You don't HAVE to write a script. But I prefer it that way. You can do it all on the command line but I prefer a script due to better readability.

pan64 05-11-2016 07:37 AM

see man rename and check the first example http://man.he.net/man1/rename


All times are GMT -5. The time now is 08:12 PM.