-   Linux - Newbie (
-   -   find and rename command (

Leath 07-30-2012 08:08 PM

find and rename command
Hi gurus,

I have this nifty command which finds and renames files wthat have a colon : in them. It works well on my ubuntu box at home, but I can't seem to get it to run properly at work. Any one have any idea why that would be and how I can get around it?

The find command on it's own returns the correct results.


find Directory_to_search/ -name "*:*" -exec rename -v 's/:/#/' {} +
Home - ubuntu build from a couple months ago.
work - CentOS 2.16.0 (old one from 2007)

On a side note - can anyone think of a reason I shouldn't replace the : with a #? I was going to use # so it was easy to revert it back later.

Thanks in advance.

Leath 07-30-2012 09:50 PM

FYI - I managed to get this working with the help of a knowledgable colleague. For this version of rename the correct method was to use single quotes as below:


find Directory_to_search/ -name "*:*" -exec rename ':' '#' {} +

chrism01 07-30-2012 10:13 PM

I'd be a bit careful of using '#', as that is the 'comment starts here' Special Char in bash (all shells actually)

Leath 07-30-2012 10:36 PM

thanks chrism01,

For the real case I replaced the colon with a distinct word which wasn't used anywhere in the files - made it easy to change and then revert the changes back.

All times are GMT -5. The time now is 08:27 AM.