LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2014, 09:11 PM   #1
kavan.shah
LQ Newbie
 
Registered: May 2014
Posts: 6

Rep: Reputation: Disabled
Shell Script required to change directories in linux


Hello Experts,

Am new to LINUX and i got a requirement from my client saying we have some 1500 sub directories in one directory(users is the name of the directory) in that directory the subdirectories starts with genpact%3akavan,genpact%3akavan.atr,genpact%3aganga,genpact%3aganga.atr,genpact%3amalik,genpact%3ama lik.atr...etc.Now i want to replace all genpact%3a with a space and the final output looks like kavan,kavan.atr,ganga,ganga.atr,malik,malik.atr.

Please help me out here,It is very urgent requirement.

Thank you very much for your help.

Regards,
Kavan.
 
Old 05-16-2014, 09:57 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,870

Rep: Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249
If your sub-directories are all in one directory and you want to change all the directories beginning with "genpact%3a" this worked when I tested it. You might create a directory and and create a few folders to test to see that it does what you want:

Code:
rename genpact%3a "" *
If some are in sub-directories of sub-directories, you'll need to do some research.

Last edited by yancek; 05-16-2014 at 10:14 PM.
 
3 members found this post helpful.
Old 05-17-2014, 02:51 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by kavan.shah View Post
Hello Experts,
Am new to LINUX and i got a requirement from my client saying we have some 1500 sub directories in one directory(users is the name of the directory) in that directory the subdirectories starts with genpact%3akavan,genpact%3akavan.atr,genpact%3aganga,genpact%3aganga.atr,genpact%3amalik,genpact%3ama lik.atr...etc.

Now i want to replace all genpact%3a with a space and the final output looks like kavan,kavan.atr,ganga,ganga.atr,malik,malik.atr.

Please help me out here,It is very urgent requirement.
Please read the posting guidelines, and the "How to ask a smart question" guidelines. This is NOT URGENT for ANYONE here...we volunteer our time, so expecting us to hurry and answer you, because YOU are in a hurry, is fairly rude. Also, if you're new to Linux...how and why, exactly, would you get a client to give you a Linux related job/task, when you don't know anything about Linux? Or is this a homework assignment?

As yancek said, the rename command can get you started...read the man page on that command. Also, a simple bash script could also do this, as could a combination of commands using find and mv, like this:
Code:
find /path -name <regex/name> -type d -execdir mv {} <regex/name> \;
 
1 members found this post helpful.
Old 05-18-2014, 05:49 PM   #4
kavan.shah
LQ Newbie
 
Registered: May 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by yancek View Post
If your sub-directories are all in one directory and you want to change all the directories beginning with "genpact%3a" this worked when I tested it. You might create a directory and and create a few folders to test to see that it does what you want:

Code:
rename genpact%3a "" *
If some are in sub-directories of sub-directories, you'll need to do some research.

Thanks yancek for your prompt response.

When am trying to do that it is showing the below error:-
rename: renaming genpact%3aabshukla to abshukla failed: Directory not empty

Please guide me what is the issue here?
 
Old 05-18-2014, 06:36 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by kavan.shah View Post
Thanks yancek for your prompt response.

When am trying to do that it is showing the below error:-
rename: renaming genpact%3aabshukla to abshukla failed: Directory not empty

Please guide me what is the issue here?
The man page tells you what the command does, and there is ample documentation on it:
http://linux.about.com/od/commands/l/blcmdl2_rename.htm

It specifically says that if the directory is not empty (that is, contains things other than the "." and ".." entries), it will error out. Since you thanked yancek for his reply, did you bother to read mine? How about the part where I handed you a working solution?

Telling people your request is 'urgent' is rude; not acknowledging help or answers is also rude.
 
Old 05-18-2014, 06:41 PM   #6
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,870

Rep: Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249
The issue is the directories are not empty and according to the site below, the rename won't work in that case.

http://www.gnu.org/software/libc/man...ing-Files.html
 
1 members found this post helpful.
Old 05-18-2014, 10:05 PM   #7
kavan.shah
LQ Newbie
 
Registered: May 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
I can see it is having 27 GB of free space in the directory.Is that not sufficient.Please guide.
 
Old 05-18-2014, 10:07 PM   #8
kavan.shah
LQ Newbie
 
Registered: May 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Can you tell me the same command we can use in windows? If space is the issue i want to copy the users directory to my local machine and check.Please help

Thanks for your help
 
Old 05-18-2014, 10:28 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by kavan.shah View Post
I can see it is having 27 GB of free space in the directory.Is that not sufficient.Please guide.
We did; we told you very clearly that the issue was because there are other files/directories under the one you're trying to rename Want it to work? Delete them, or use the command that I handed you, and you have not even acknowledged.
Quote:
Originally Posted by kavan.shah
Can you tell me the same command we can use in windows? If space is the issue i want to copy the users directory to my local machine and check.Please help
This is LinuxQuestions...for help with Windows, you may want to try a Windows-related forum. And AGAIN, space is not the issue.
 
1 members found this post helpful.
Old 05-18-2014, 10:34 PM   #10
kavan.shah
LQ Newbie
 
Registered: May 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
TB0ne,

Am sorry if my words are rash or hurts you.

I already told you,am new to this linux.Could you elabroate how to use this command?

find /path -name <regex/name> -type d -execdir mv {} <regex/name> \;
 
Old 05-19-2014, 11:18 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by kavan.shah View Post
TB0ne,
Am sorry if my words are rash or hurts you.
Not hurtful at all, but you have been RUDE, period.
Quote:
I already told you,am new to this linux.
And I asked how you could get a client/task to perform Linux-related work, when (as you said), are new to Linux. Especially, how could you get an 'urgent' task to accomplish? As I said before, this seems VERY much like a homework assignment.
Quote:
Could you elabroate how to use this command?

find /path -name <regex/name> -type d -execdir mv {} <regex/name> \;
You use it by typing it in...doesn't get much more simple than that. Replace the names/regex with whatever your criteria are.
 
Old 05-19-2014, 02:00 PM   #12
kavan.shah
LQ Newbie
 
Registered: May 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
It is not working.Correct me if am doing wrong.

-ksh: genpact%3a: cannot open [No such file or directory]
 
Old 05-19-2014, 02:52 PM   #13
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
You are in the korn shell,.. perhaps try running bash first.

Code:
/bin/bash
Then try running the command above again. Or failing that,. just put the directory name in quotes:

Code:
find /path -name "<regex/name>" -type d -execdir mv {} "<regex/name>" \;

Last edited by szboardstretcher; 05-19-2014 at 02:55 PM.
 
  


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
LXer: Change to your Favorite directories on the bash shell by scripting cd. LXer Syndicated Linux News 0 07-11-2010 05:10 PM
[SOLVED] Shell script for recursive delete required. bikbjrt Linux - Newbie 2 07-01-2010 01:25 AM
Shell script assistance required.. TheEngineer Linux - Newbie 4 10-26-2006 07:42 AM
shell script help required syntax error sridhar11 Programming 1 10-31-2005 09:38 AM
small shell script required demigor Programming 6 08-08-2005 05:38 PM


All times are GMT -5. The time now is 07:04 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration