I have about 1000 files containing the character * in the name. I need to find these files and replace the * with a -. I am working with HP UX v11. I am using the following command

find . -type f -name '*\**' -exec bash -c 'f="$1"; mv "$f" "${f//\*/-}"' - '{}' \;

I am told it works but for me it renames the complete file to - instead of replacing the *.

GNU bash, version 2.04.0(1)-release (hppa2.0w-hp-hpux11.00)

  • Make sure you're running it under BASH. Also can you check your BASH version on your HP host? – anubhava Jan 8 '14 at 19:30
  • Thank you I updated the question with the bash version info – RustywithUnix Jan 8 '14 at 19:32
  • Ok that is pretty old BASH. Can you run find . -type f -name '*\**' to see if it lists correct files. – anubhava Jan 8 '14 at 19:37
  • Yes that lists the correct files. The problem lies with the renaming once found. – RustywithUnix Jan 8 '14 at 19:52
  • 1
    I upgraded to bash 4.2 and the original command works – RustywithUnix Jan 8 '14 at 20:26

Try this command find command:

find . -type f -name '*\**' -exec bash -c 'f="$1"; echo mv "$f" `echo "$f"|tr "\*" "-"`' - '{}' \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.