LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 05-10-2016, 11:58 PM   #1
sco1984
Member
 
Registered: Sep 2005
Location: Pune, India
Distribution: openSUSE Leap
Posts: 137

Rep: Reputation: 15
Question 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.
 
Old 05-11-2016, 01:12 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
have you checked the command rename?
 
Old 05-11-2016, 06:30 AM   #3
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by sco1984 View Post
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
 
Old 05-11-2016, 06:54 AM   #4
sco1984
Member
 
Registered: Sep 2005
Location: Pune, India
Distribution: openSUSE Leap
Posts: 137

Original Poster
Rep: Reputation: 15
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
 
Old 05-11-2016, 07:20 AM   #5
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.

Last edited by HMW; 05-11-2016 at 07:33 AM.
 
Old 05-11-2016, 07:37 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Rename all folders in a directory to lowercase? Squerl101 Linux - Software 2 06-23-2013 09:21 AM
recursive rename of folders BreezyBadger Linux - Newbie 3 06-14-2012 06:08 PM
[SOLVED] rename files in folders using perl script pablgonz Programming 15 12-18-2011 12:22 PM
Cannot rename or delete image folders Neo727 Linux - Newbie 3 05-28-2011 05:32 PM
Rename multiple files in folders??? adds2one Linux - Software 19 10-05-2006 12:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 12:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration