Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you read through the <code>-exec</code> section of the <code>man</code> pages for <code>find</code> you will come across the <code>{}</code> string that allows you to use the matches as arguments within <code>-exec</code>. This will allow you to use <code>rename</code> on your <code>find</code> matches in the following way:</p> <pre><code>find . -name 'file_*' -exec rename 's/file_/mywish_/' {} \; </code></pre> <p>From the manual:</p> <blockquote> <p>-exec <strong>command</strong> ;</p> <p>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 <code>;' is encountered. The string</code>{}' 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.</p> </blockquote> <p>Although you asked for a find/exec solution, as <a href="https://stackoverflow.com/users/797049/mark-reed">Mark Reed</a> suggested, you might want to consider piping your results to <code>xargs</code>. If you do, make sure to use the <code>-print0</code> option with <code>find</code> and either the <code>-0</code> or <code>-null</code> option with <code>xargs</code> to avoid unexpected behaviour resulting from whitespace or shell metacharacters appearing in your file names. Also, consider using the <code>+</code> version of <code>-exec</code> (also in the manual) as this is the POSIX spec for <code>find</code> and should therefore be more portable if you are wanting to run your command elsewhere (not <strong>always</strong> true); it also builds its command line in a way similar to <code>xargs</code> which should result in less invocations of <code>rename</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload