hankknight
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!
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!
rename abc xyz *
ASKER
Thanks, how can this be done recursively so it changes files in all subdirectories?
#!/usr/bin/bash
find . -name '*abc*' -print | while read f ; do mv $f ${f/abc/xyz} ; done
find . -name '*abc*' -print | while read f ; do mv $f ${f/abc/xyz} ; done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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" ...
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 :-(