Thursday, January 25, 2018

bash - Finding and renaming files


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)


Answer



Try this command find command:


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

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...