Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697880
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:54:49+00:00 2026-05-19T04:54:49+00:00

I have a folder structure, as shown below: I need to create a bash

  • 0

I have a folder structure, as shown below:

alt text

I need to create a bash script that does 4 things:

  1. It searches all the files in the generic directory and finds the string ‘generic’ and makes it into ‘something’
  2. As above, but changes "GENERIC" to "SOMETHING"
  3. As above, but changes "Generic" to "Something"
  4. Renames any filename that has "generic" in it with "something"

Right now I am doing this process manually by using the search and replace in net beans. I dont know much about bash scripting, but i’m sure this can be done. I’m thinking of something that I would run and it would take "Something" as the input.

Where would I start? what functions should I use? overall guidance would be great. thanks.

I am using Ubuntu 10.5 desktop edition.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:54:49+00:00Added an answer on May 19, 2026 at 4:54 am

    Editing

    The substitution part is a sed script – call it mapname:

    sed -i.bak \
        -e 's/generic/something/g' \
        -e 's/GENERIC/SOMETHING/g' \
        -e 's/Generic/Something/g "$@"
    

    Note that this will change words in comments and strings too, and it will change ‘generic’ as part of a word rather than just the whole word. If you want just the word, then you use end-word markers around the terms: 's/\<generic\>/something/g'. The -i.bak creates backups.

    You apply that with:

    find . -type f -exec mapname {} +
    

    That creates a command with a list of files and executes it. Clearly, you can, if you prefer, avoid the intermediate mapname shell/sed script (by writing the sed script in place of the word mapname in the find command). Personally, I prefer to debug things separately.

    Renaming

    The renaming of the files is best done with the rename command – of which there are two variants, so you’ll need to read your manual. Use one of these two:

    find . -name '*generic*' -depth -exec rename   generic something   {} +
    
    find . -name '*generic*' -depth -exec rename s/generic/something/g {} +
    

    (Thanks to Stephen P for pointing out that I was using a more powerful Perl-based variant of rename with full Perl regexp capacity, and to Zack and Jefromi for pointing out that the Perl one is found in the real world* too.)

    Notes:

    • This renames directories.
    • It is probably worth keeping the -depth in there so that the contents of the directories are renamed before the directories; you could otherwise get messages because you rename the directory and then can’t locate the files in it (because find gave you the old name to work with).
    • The more basic rename will move ./generic/do_generic.java to ./something/do_generic.java only. You’d need to run the command more than once to get every component of every file name changed.

    * The version of rename that I use is adapted from code in the 1st Edition of the Camel book.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder that is my working copy. How do I remove all
I have a folder, c:\websites\test , and it contains folders and files that were
I have a folder in NTFS that contains tens of thousands of files. I've
I am using PHP and I need to script something like below: I have
I have an application that was in a folder named project, I moved all
If I have a folder structure set up like this: ~/Projects emacs package1 package1-helpers
I have a folder with these files: alongfilename1.txt <--- created first alongfilename3.txt <--- created
i just want to know about the files and folder structure for a site
I have a Java project which has this file structure (shown in Eclipse): ProjectName
I create a menu structure from a compiled class that returns an unordered list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.