How can I replace a string in all filenames in a directory? (specifically I need to remove "\#015" from all file names in a directory How can I replace a string in all filenames in a directory? (specifically I need to remove "\#015" from all file names in a directory unix unix

How can I replace a string in all filenames in a directory? (specifically I need to remove "\#015" from all file names in a directory


for file in *\#015do   mv -- "$file" "${file%\#015}"done

You may need to escape the "\"s. Try it in a tmp directory first.


If you have rename installed, this becomes a fairly simple task:

rename 's/\\#015$//' /root/path/*\\#015

You can add the -f flag to force overwriting existing files if necessary.


This is how I'd solved a similar problem in the past with a little shell.

cd /root/path/ls | grep '\#015' | sed 's/\(.*\)\\#015/mv & \1/' | sh