Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Find and replace for file names (recursive)

Hello,

I would like to change ALL filenames in a directory recursively that contain abc in the anywhere in the filename.

All instances of "abc" should be changed to "xyz"

So:
  abc.jsp should be changed to xyz.jsp
  babc.sh should be changed to bxyz.sh
  iknow.myabcs.pdf should be changed to iknow.myxyzs.pdf

How can I do this for all files in a directory and all files in subdirectories of that directory?

Thanks!
Avatar of ghostdog74
ghostdog74

rename abc xyz  *
Avatar of hankknight

ASKER

Thanks, how can this be done recursively so it changes files in all subdirectories?
Avatar of ozo
#!/usr/bin/bash
find . -name '*abc*' -print | while read f ; do mv $f ${f/abc/xyz} ; done
ASKER CERTIFIED SOLUTION
Avatar of stetor
stetor
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
find . -name "abc*" -exec rename abc xyz {} \;
tintin, your statment change only the filename that start with "abc" and only change  the first instance
of  "abc" whereas hankknight say "All instances of "abc" " and "anywhere in the filename"  ...


You're correct stetor.  I didn't read the question carefully enough :-(