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.
I managed to find several files with the find command. the files are of
Share
If you read through the
-execsection of themanpages forfindyou will come across the{}string that allows you to use the matches as arguments within-exec. This will allow you to userenameon yourfindmatches in the following way:From the manual:
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-print0option withfindand either the-0or-nulloption withxargsto 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 forfindand 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 toxargswhich should result in less invocations ofrename.