copy files with new extension in same directory

I've been able to find all the extensionless files named photos using the command:

find /usr/local/apache/htdocs -name photos -print0

I need to copy those files to the name photos.php in their same directory.

I've found a bunch of xarg examples for moving to other directories but I wasn't sure how to keep them in their original directory. I also want to make sure that permissions and ownership remain the same.

Many thanks for any advice.

How many files are you getting can you list all of them along with there name...!!!!

find .... | xargs -I{} mv {} {}.php

(replace mv with cp if you want to copy, and not rename, the files)

When I ran:

find /usr/local/apache/htdocs -name photos -print0 | xargs -I{} cp {} {}.php

I got a "xargs: invalid option -- I".

Looks like I have an older version of xargs. Off to upgrade! :slight_smile:

Eeks! Try it with a lowercase i.

find .... | xargs -i mv {} {}.php

Running

find /usr/local/apache/htdocs -name photos -print0 | xargs -i{} cp {} {}.php

gave me the following:

cp: `/usr/local/apache/htdocs/academy/73/photos' and `/usr/local/apache/htdocs/academy/73/photos' are the same file.

:frowning:

It's the old "it works for me" thing :slight_smile: - but I didn't use the -print0 option (because AIX find doesn't support it!)

I don't know just how old your xargs is, but try either using -n1 with it, or removing the -print0 option from the find command.

1 Like

Dropping the -print0 worked like a charm.

Thanks!