Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

325
Views
How to run mv command run recursively in Linux

My environment: Bash 3.5 LinuxRedhat

I'm using the following code to rename all of my files in a single directory.

for file in *.* ; do mv "$file" "Add_$file" ; done

Now, I want to rename my file recursively.And I don't know how to do.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The first ideas with find don't work, because {} returns ./ with the command:

find . -type f -name "*.*" -execdir mv {} Add_{} ";"

We need something, which removes the ./ in front but works in subdirectories too.

echo 'f=$(basename "$1"); mv "$f" Add_"$f";' > adhoc.sh
chmod a+x adhoc.sh
find . -type f -name "*.*" -execdir $PWD/adhoc.sh "{}" ";"

At least this works for gnu-find. Other finds might not have an -execdir command.

Thanks for skyking for pointing my error out.

For Linux, you might find a version of 'rename' in the repository, but normally it has to be installed and isn't part of the standard installation. If you often rename with the commandline, it is worth the effort. With rename, you specify a regex substitute command and can test it first:

find . -type f -exec rename -n "s/(.*)/Add_\1/" {} ";" 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!