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 8678071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:37:08+00:00 2026-06-12T20:37:08+00:00

I managed to find several files with the find command. the files are of

  • 0

I managed to find several files with the find command.
the files are of the type file_sakfksanf.txt, file_afsjnanfs.pdf, file_afsnjnjans.cpp,
now I want to rename them with the rename and -exec command to
mywish_sakfksanf.txt, mywish_afsjnanfs.pdf, mywish_afsnjnjans.cpp
that only the first prefix is changed. I am trying for some time, so don’t blame me for being stupid.

  • 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-06-12T20:37:10+00:00Added an answer on June 12, 2026 at 8:37 pm

    If you read through the -exec section of the man pages for find you will come across the {} string that allows you to use the matches as arguments within -exec. This will allow you to use rename on your find matches in the following way:

    find . -name 'file_*' -exec rename 's/file_/mywish_/' {} \;
    

    From the manual:

    -exec command ;

    Execute command; true if 0 status is returned. All following
    arguments to find are taken to be arguments to the command until an
    argument consisting of ;' is encountered. The string{}’ is replaced
    by the current file name being processed everywhere it occurs in the
    arguments to the command, not just in arguments where it is alone, as
    in some versions of find. Both of these constructions might need to
    be escaped (with a `\’) or quoted to protect them from expansion by
    the shell. See the EXAMPLES section for examples of the use of the
    -exec option. The specified command is run once for each matched file. The command is executed in the starting directory.There are
    unavoidable security problems surrounding use of the -exec action;
    you should use the -execdir option instead.

    Although you asked for a find/exec solution, as Mark Reed suggested, you might want to consider piping your results to xargs. If you do, make sure to use the -print0 option with find and either the -0 or -null option with xargs to avoid unexpected behaviour resulting from whitespace or shell metacharacters appearing in your file names. Also, consider using the + version of -exec (also in the manual) as this is the POSIX spec for find and should therefore be more portable if you are wanting to run your command elsewhere (not always true); it also builds its command line in a way similar to xargs which should result in less invocations of rename.

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

Sidebar

Related Questions

Below are the only instructions I managed to find from Google on how to
I'm so stuck with a problem and I haven't yet managed to find the
I've been looking around, and so far haven't managed to find a good way
Is it possible to perform a global reversed-find on NHibernate-managed objects? Specifically, I have
I can't find a solution for that. I managed to solve the problem of
We have several fairly large JavaScript files embedded into a single script resources DLL.
On my web site I would like to have several sub-domains. Files that create
I have an app that relies on several managed libraries. These managed libraries in
I suspect this is a fairly simple concept, but I haven't managed to find
I have an Ajax form, which loads several files; the problem is that Request.Files

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.