LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-25-2014, 03:46 AM   #1
vkejriwal
LQ Newbie
 
Registered: Jan 2014
Posts: 3

Rep: Reputation: Disabled
Shell Scripting


Hi Team ,

I have a file containg folders and files . Now file and folders have different name like vishal , gaurav , abcvishalabc , xyvishalxyz1 .

I need to file all the file name containg vishal and replace vishal with mayank .

So all my file and folders will have name mayank , gaurav, abcmayankabc , xymayankxyz1.

please help me to write the script.

Help will be appreciated.
 
Old 01-25-2014, 03:52 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
What have you tried and what seems to give you problems?

Looking for specific files and/or directories can be done with the find command. It would also be possible to rename (move) files using find.
 
Old 01-25-2014, 03:59 AM   #3
vkejriwal
LQ Newbie
 
Registered: Jan 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Angry

i am using this command to find all the files and folder containg substring vishal
find . -name "*vishal*"

Now i am not able to find the command to change the file conating vishal with mayank and to too recursive.
 
Old 01-25-2014, 04:17 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Did you have a good look at the link I provided?

- The find command is recursive by nature, no need to specify it.
- The -exec ..... option can be used to execute commands (find -> -exec)

BTW: If you are looking specifically for files (or directories) you might want to include the -type xyz option.
 
Old 01-25-2014, 04:26 AM   #5
vkejriwal
LQ Newbie
 
Registered: Jan 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
i am not looking for specific file type, looking for a file or directory whose name contain vishal.
I am new to this shell scripting and got confused
 
Old 01-25-2014, 04:45 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Quote:
Originally Posted by vkejriwal View Post
i am not looking for specific file type, looking for a file or directory whose name contain vishal.
Yes, you told us that already
Quote:
I am new to this shell scripting and got confused
As suggested before: Take the time to read this link: find. All the answers you seek are there and with the hints I gave in my previous post you should be able to come up with a solution.

I'm not going to spoon feed you because this looks a lot like homework.
 
1 members found this post helpful.
  


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
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-13-2013 12:20 AM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:13 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